FrankChen021 commented on code in PR #20724:
URL: https://github.com/apache/druid/pull/20724#discussion_r4373778557


##########
server/src/test/java/org/apache/druid/server/coordinator/balancer/ReservoirSegmentSamplerTest.java:
##########
@@ -279,15 +279,32 @@ public void 
testSegmentsFromMorePopulousServerAreMoreLikelyToBePicked()
 
       // 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)

Review Comment:
   let's keep using 4



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to