From d00af73f9d611492085e04e0e2a0b25523a00672 Mon Sep 17 00:00:00 2001 From: Almas Abdrazak Date: Tue, 2 Dec 2025 15:12:48 -0800 Subject: [PATCH] JAVA-4320 fix server selection flaky test --- .../mongodb/client/AbstractServerSelectionProseTest.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/driver-sync/src/test/functional/com/mongodb/client/AbstractServerSelectionProseTest.java b/driver-sync/src/test/functional/com/mongodb/client/AbstractServerSelectionProseTest.java index 506a40d8bd6..e021137b9a8 100644 --- a/driver-sync/src/test/functional/com/mongodb/client/AbstractServerSelectionProseTest.java +++ b/driver-sync/src/test/functional/com/mongodb/client/AbstractServerSelectionProseTest.java @@ -72,7 +72,7 @@ void operationCountBasedSelectionWithinLatencyWindow() throws InterruptedExcepti String appName = "loadBalancingTest"; int timeoutSeconds = 60; int tasks = 10; - int opsPerTask = 100; + int opsPerTask = 1000; // it used to be 100 but NodeJs driver has 1000 TestCommandListener commandListener = new TestCommandListener(singletonList("commandStartedEvent"), singletonList("drop")); MongoClientSettings clientSettings = getMongoClientSettingsBuilder() .applicationName(appName) @@ -109,7 +109,10 @@ void operationCountBasedSelectionWithinLatencyWindow() throws InterruptedExcepti commandListener.reset(); Map selectionRates = doSelections(collection, commandListener, executor, tasks, opsPerTask, timeoutSeconds); - selectionRates.values().forEach(rate -> assertEquals(0.5, rate, 0.1, selectionRates::toString)); + // assert that each mongos was selected roughly 50% of the time (within +/- 15%). + // the specification says within 10% but in practice + // the deviation can be higher , Nodejs driver uses 15% and has not seen failures with that threshold + selectionRates.values().forEach(rate -> assertEquals(0.5, rate, 0.15, selectionRates::toString)); } finally { executor.shutdownNow(); assertTrue(executor.awaitTermination(timeoutSeconds, SECONDS));