Skip to content

Commit

Permalink
Fix RandomSamplerAggregatorTests testAggregationSamplingNestedAggsSca…
Browse files Browse the repository at this point in the history
…led test failure (#89958)

This test indexes 150 documents. In case the test index has a high number of segments,
it can happen that no documents get sampled. I think this is expected behaviour in this case.

This commit adds a special case for this situation, by expecting other counts to be 0 if sampled
doc count is 0 as well.

Closes #89818
  • Loading branch information
martijnvg authored Sep 9, 2022
1 parent 77c9e2d commit 258833f
Showing 1 changed file with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,18 @@ public void testAggregationSamplingNestedAggsScaled() throws IOException {
long outerFilterDocCount = agg.getDocCount();
Filter innerAgg = agg.getAggregations().get("filter_inner");
long innerFilterDocCount = innerAgg.getDocCount();
// subaggs should be scaled along with upper level aggs
assertThat(outerFilterDocCount, equalTo(innerFilterDocCount));
// sampled doc count is NOT scaled, and thus should be lower
assertThat(outerFilterDocCount, greaterThan(sampledDocCount));
if (sampledDocCount == 0) {
// in case 0 docs get sampled, which can rarely happen
// in case the test index has many segments.
assertThat(sampledDocCount, equalTo(0L));
assertThat(innerFilterDocCount, equalTo(0L));
assertThat(outerFilterDocCount, equalTo(0L));
} else {
// subaggs should be scaled along with upper level aggs
assertThat(outerFilterDocCount, equalTo(innerFilterDocCount));
// sampled doc count is NOT scaled, and thus should be lower
assertThat(outerFilterDocCount, greaterThan(sampledDocCount));
}
},
longField(NUMERIC_FIELD_NAME),
keywordField(KEYWORD_FIELD_NAME)
Expand Down

0 comments on commit 258833f

Please sign in to comment.