Skip to content

Commit b63a4f3

Browse files
authored
Fix aggs integration tests where buckets can be empty (#4169)
This commit fixes integration tests for aggregations that use a date_histogram aggregation, where a bucker may have no documents with a specific seed value. For example, build.bat seed:41075 integrate 7.4.0 "readonly"
1 parent e24d743 commit b63a4f3

File tree

7 files changed

+26
-5
lines changed

7 files changed

+26
-5
lines changed

src/Tests/Tests/Aggregations/Pipeline/BucketScript/BucketScriptAggregationUsageTests.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public BucketScriptAggregationUsageTests(ReadOnlyCluster cluster, EndpointUsage
2020
{
2121
field = "startedOn",
2222
interval = "month",
23+
min_doc_count = 1
2324
},
2425
aggs = new
2526
{
@@ -77,6 +78,7 @@ public BucketScriptAggregationUsageTests(ReadOnlyCluster cluster, EndpointUsage
7778
.DateHistogram("projects_started_per_month", dh => dh
7879
.Field(p => p.StartedOn)
7980
.Interval(DateInterval.Month)
81+
.MinimumDocumentCount(1)
8082
.Aggregations(aa => aa
8183
.Sum("commits", sm => sm
8284
.Field(p => p.NumberOfCommits)
@@ -106,6 +108,7 @@ public BucketScriptAggregationUsageTests(ReadOnlyCluster cluster, EndpointUsage
106108
{
107109
Field = "startedOn",
108110
Interval = DateInterval.Month,
111+
MinimumDocumentCount = 1,
109112
Aggregations =
110113
new SumAggregation("commits", "numberOfCommits") &&
111114
new FilterAggregation("stable_state")

src/Tests/Tests/Aggregations/Pipeline/Derivative/DerivativeAggregationUsageTests.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public DerivativeAggregationUsageTests(ReadOnlyCluster cluster, EndpointUsage us
2121
{
2222
field = "startedOn",
2323
interval = "month",
24+
min_doc_count = 1
2425
},
2526
aggs = new
2627
{
@@ -47,6 +48,7 @@ public DerivativeAggregationUsageTests(ReadOnlyCluster cluster, EndpointUsage us
4748
.DateHistogram("projects_started_per_month", dh => dh
4849
.Field(p => p.StartedOn)
4950
.Interval(DateInterval.Month)
51+
.MinimumDocumentCount(1)
5052
.Aggregations(aa => aa
5153
.Sum("commits", sm => sm
5254
.Field(p => p.NumberOfCommits)
@@ -62,6 +64,7 @@ public DerivativeAggregationUsageTests(ReadOnlyCluster cluster, EndpointUsage us
6264
{
6365
Field = "startedOn",
6466
Interval = DateInterval.Month,
67+
MinimumDocumentCount = 1,
6568
Aggregations =
6669
new SumAggregation("commits", "numberOfCommits") &&
6770
new DerivativeAggregation("commits_derivative", "commits")

src/Tests/Tests/Aggregations/Pipeline/MovingAverage/MovingAverageEwmaAggregationUsageTests.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public MovingAverageEwmaAggregationUsageTests(ReadOnlyCluster cluster, EndpointU
2323
{
2424
field = "startedOn",
2525
interval = "month",
26+
min_doc_count = 1
2627
},
2728
aggs = new
2829
{
@@ -54,6 +55,7 @@ public MovingAverageEwmaAggregationUsageTests(ReadOnlyCluster cluster, EndpointU
5455
.DateHistogram("projects_started_per_month", dh => dh
5556
.Field(p => p.StartedOn)
5657
.Interval(DateInterval.Month)
58+
.MinimumDocumentCount(1)
5759
.Aggregations(aa => aa
5860
.Sum("commits", sm => sm
5961
.Field(p => p.NumberOfCommits)
@@ -74,6 +76,7 @@ public MovingAverageEwmaAggregationUsageTests(ReadOnlyCluster cluster, EndpointU
7476
{
7577
Field = "startedOn",
7678
Interval = DateInterval.Month,
79+
MinimumDocumentCount = 1,
7780
Aggregations =
7881
new SumAggregation("commits", "numberOfCommits")
7982
&& new MovingAverageAggregation("commits_moving_avg", "commits")

src/Tests/Tests/Aggregations/Pipeline/MovingAverage/MovingAverageHoltLinearAggregationUsageTests.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ public MovingAverageHoltLinearAggregationUsageTests(ReadOnlyCluster cluster, End
2222
date_histogram = new
2323
{
2424
field = "startedOn",
25-
interval = "month"
25+
interval = "month",
26+
min_doc_count = 1
2627
},
2728
aggs = new
2829
{
@@ -55,6 +56,7 @@ public MovingAverageHoltLinearAggregationUsageTests(ReadOnlyCluster cluster, End
5556
.DateHistogram("projects_started_per_month", dh => dh
5657
.Field(p => p.StartedOn)
5758
.Interval(DateInterval.Month)
59+
.MinimumDocumentCount(1)
5860
.Aggregations(aa => aa
5961
.Sum("commits", sm => sm.Field(p => p.NumberOfCommits))
6062
.MovingAverage("commits_moving_avg", mv => mv
@@ -74,6 +76,7 @@ public MovingAverageHoltLinearAggregationUsageTests(ReadOnlyCluster cluster, End
7476
{
7577
Field = "startedOn",
7678
Interval = DateInterval.Month,
79+
MinimumDocumentCount = 1,
7780
Aggregations =
7881
new SumAggregation("commits", "numberOfCommits")
7982
&& new MovingAverageAggregation("commits_moving_avg", "commits")

src/Tests/Tests/Aggregations/Pipeline/MovingAverage/MovingAverageHoltWintersAggregationUsageTests.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ public MovingAverageHoltWintersUsageTests(ReadOnlyCluster cluster, EndpointUsage
2121
date_histogram = new
2222
{
2323
field = "startedOn",
24-
interval = "month"
24+
interval = "month",
25+
min_doc_count = 1
2526
},
2627
aggs = new
2728
{
@@ -59,6 +60,7 @@ public MovingAverageHoltWintersUsageTests(ReadOnlyCluster cluster, EndpointUsage
5960
.DateHistogram("projects_started_per_month", dh => dh
6061
.Field(p => p.StartedOn)
6162
.Interval(DateInterval.Month)
63+
.MinimumDocumentCount(1)
6264
.Aggregations(aa => aa
6365
.Sum("commits", sm => sm
6466
.Field(p => p.NumberOfCommits)
@@ -85,6 +87,7 @@ public MovingAverageHoltWintersUsageTests(ReadOnlyCluster cluster, EndpointUsage
8587
{
8688
Field = "startedOn",
8789
Interval = DateInterval.Month,
90+
MinimumDocumentCount = 1,
8891
Aggregations =
8992
new SumAggregation("commits", "numberOfCommits")
9093
&& new MovingAverageAggregation("commits_moving_avg", "commits")
@@ -124,7 +127,7 @@ protected override void ExpectResponse(ISearchResponse<Project> response)
124127
var movingAverage = item.MovingAverage("commits_moving_avg");
125128

126129
// Moving Average specifies a window of 4 so
127-
// moving average values should exist from 5th bucketr onwards
130+
// moving average values should exist from 5th bucket onwards
128131
if (bucketCount <= 4)
129132
movingAverage.Should().BeNull();
130133
else

src/Tests/Tests/Aggregations/Pipeline/MovingAverage/MovingAverageSimpleAggregationUsageTests.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public MovingAverageSimpleAggregationUsageTests(ReadOnlyCluster cluster, Endpoin
2222
date_histogram = new
2323
{
2424
field = "startedOn",
25-
interval = "month",
25+
interval = "month"
2626
},
2727
aggs = new
2828
{
@@ -41,6 +41,7 @@ public MovingAverageSimpleAggregationUsageTests(ReadOnlyCluster cluster, Endpoin
4141
model = "simple",
4242
window = 30,
4343
predict = 10,
44+
gap_policy = "insert_zeros",
4445
settings = new { }
4546
}
4647
}
@@ -61,6 +62,7 @@ public MovingAverageSimpleAggregationUsageTests(ReadOnlyCluster cluster, Endpoin
6162
.BucketsPath("commits")
6263
.Window(30)
6364
.Predict(10)
65+
.GapPolicy(GapPolicy.InsertZeros)
6466
.Model(m => m
6567
.Simple()
6668
)
@@ -79,6 +81,7 @@ public MovingAverageSimpleAggregationUsageTests(ReadOnlyCluster cluster, Endpoin
7981
{
8082
Window = 30,
8183
Predict = 10,
84+
GapPolicy = GapPolicy.InsertZeros,
8285
Model = new SimpleModel()
8386
}
8487
};

src/Tests/Tests/Aggregations/Pipeline/SerialDifferencing/SerialDifferencingAggregationUsageTests.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ public SerialDifferencingAggregationUsageTests(ReadOnlyCluster cluster, Endpoint
1919
date_histogram = new
2020
{
2121
field = "startedOn",
22-
interval = "month"
22+
interval = "month",
23+
min_doc_count = 1
2324
},
2425
aggs = new
2526
{
@@ -47,6 +48,7 @@ public SerialDifferencingAggregationUsageTests(ReadOnlyCluster cluster, Endpoint
4748
.DateHistogram("projects_started_per_month", dh => dh
4849
.Field(p => p.StartedOn)
4950
.Interval(DateInterval.Month)
51+
.MinimumDocumentCount(1)
5052
.Aggregations(aa => aa
5153
.Sum("commits", sm => sm
5254
.Field(p => p.NumberOfCommits)
@@ -63,6 +65,7 @@ public SerialDifferencingAggregationUsageTests(ReadOnlyCluster cluster, Endpoint
6365
{
6466
Field = "startedOn",
6567
Interval = DateInterval.Month,
68+
MinimumDocumentCount = 1,
6669
Aggregations =
6770
new SumAggregation("commits", "numberOfCommits")
6871
&& new SerialDifferencingAggregation("second_difference", "commits")

0 commit comments

Comments
 (0)