This is an automated email from the ASF dual-hosted git repository.
FrankChen021 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/druid.git
The following commit(s) were added to refs/heads/master by this push:
new 434de02b20f test: fix flaky ReservoirSegmentSamplerTest tolerance
(#20724)
434de02b20f is described below
commit 434de02b20f69fb2476bb6d1f13f7ad66ebe37d8
Author: Mahesh Rijal <[email protected]>
AuthorDate: Mon Oct 26 09:20:03 2026 +0530
test: fix flaky ReservoirSegmentSamplerTest tolerance (#20724)
* test: fix flaky ReservoirSegmentSamplerTest tolerance
* test: apply statistical tolerance to equal-server sampler test
---
.../balancer/ReservoirSegmentSamplerTest.java | 25 ++++++++++++++++++----
1 file changed, 21 insertions(+), 4 deletions(-)
diff --git
a/server/src/test/java/org/apache/druid/server/coordinator/balancer/ReservoirSegmentSamplerTest.java
b/server/src/test/java/org/apache/druid/server/coordinator/balancer/ReservoirSegmentSamplerTest.java
index 394d7ca9c48..54aa831f048 100644
---
a/server/src/test/java/org/apache/druid/server/coordinator/balancer/ReservoirSegmentSamplerTest.java
+++
b/server/src/test/java/org/apache/druid/server/coordinator/balancer/ReservoirSegmentSamplerTest.java
@@ -248,7 +248,7 @@ public class ReservoirSegmentSamplerTest
// Number of segments picked from each server is ~25% of total
final double expectedPickedSegments = totalSegmentsPicked * 0.25;
- final double error = totalSegmentsPicked * 0.02;
+ final double error = allowedError(totalSegmentsPicked, 0.25);
for (int pickedSegments : numSegmentsPickedFromServer) {
Assertions.assertEquals(expectedPickedSegments, pickedSegments, error);
}
@@ -279,15 +279,32 @@ public class ReservoirSegmentSamplerTest
// Number of segments picked from server0 are ~40% of total and
// number of segments picked from other servers are each ~20% of total
- double error = totalSegmentsPicked * 0.02;
- Assertions.assertEquals(totalSegmentsPicked * 0.40,
numSegmentsPickedFromServer[0], error);
+ Assertions.assertEquals(
+ totalSegmentsPicked * 0.40,
+ numSegmentsPickedFromServer[0],
+ allowedError(totalSegmentsPicked, 0.40)
+ );
for (int serverId = 1; serverId < servers.size(); ++serverId) {
- Assertions.assertEquals(totalSegmentsPicked * 0.20,
numSegmentsPickedFromServer[serverId], error);
+ Assertions.assertEquals(
+ totalSegmentsPicked * 0.20,
+ numSegmentsPickedFromServer[serverId],
+ allowedError(totalSegmentsPicked, 0.20)
+ );
}
}
}
+ /**
+ * Returns 4 standard deviations of a binomial count with {@code numPicked}
trials
+ * and probability {@code p}. A fixed percentage of {@code numPicked} is too
tight
+ * for small samples and makes the test flaky.
+ */
+ private static double allowedError(int numPicked, double p)
+ {
+ return 4 * Math.sqrt(numPicked * p * (1 - p));
+ }
+
@Test
@Timeout(value = 60_000, unit = TimeUnit.MILLISECONDS, threadMode =
ThreadMode.SEPARATE_THREAD)
public void testNumberOfSamplingsRequiredToPickAllSegments()
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]