Skip to content

Commit 489f389

Browse files
committed
Fix incremental reduce randomization in base tests cases
We can and should randomly reduce down to a single result before we passing the aggs to the final reduce. This commit changes the logic to do that and ensures we don't trip the assertions the previous imple tripped. Relates to #23253
1 parent 3a0fc52 commit 489f389

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

core/src/test/java/org/elasticsearch/search/aggregations/AggregatorTestCase.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,9 @@ protected <A extends InternalAggregation, C extends Aggregator> A searchAndReduc
180180
if (aggs.isEmpty()) {
181181
return null;
182182
} else {
183-
if (aggs.size() > 2 && randomBoolean()) {
183+
if (randomBoolean()) {
184184
// sometimes do an incremental reduce
185-
List<InternalAggregation> internalAggregations = randomSubsetOf(randomIntBetween(2, aggs.size()-1), aggs);
185+
List<InternalAggregation> internalAggregations = randomSubsetOf(randomIntBetween(1, aggs.size()), aggs);
186186
A internalAgg = (A) aggs.get(0).doReduce(internalAggregations,
187187
new InternalAggregation.ReduceContext(root.context().bigArrays(), null, false));
188188
aggs.removeAll(internalAggregations);

core/src/test/java/org/elasticsearch/search/aggregations/InternalAggregationTestCase.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,9 @@ public final void testReduceRandom() {
5757
inputs.add(t);
5858
toReduce.add(t);
5959
}
60-
if (randomBoolean() && toReduceSize >= 2) {
61-
List<InternalAggregation> internalAggregations = randomSubsetOf(randomIntBetween(2, toReduceSize - 2), toReduce);
60+
if (randomBoolean()) {
61+
// we leave at least one in the list
62+
List<InternalAggregation> internalAggregations = randomSubsetOf(randomIntBetween(1, toReduceSize), toReduce);
6263
InternalAggregation.ReduceContext context = new InternalAggregation.ReduceContext(null, null, true);
6364
@SuppressWarnings("unchecked")
6465
T reduced = (T) inputs.get(0).reduce(internalAggregations, context);

core/src/test/java/org/elasticsearch/search/aggregations/metrics/InternalExtendedStatsTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import java.util.List;
3131
import java.util.Map;
3232

33-
public class InternalExtendedStatsTests extends InternalAggregationTestCase<InternalExtendedStats> {
33+
public class InternalExtendedStatsTests extends InternalAggregationTestCase<InternalExtendedStats> {
3434
private double sigma;
3535

3636
@Before

0 commit comments

Comments
 (0)