From 3e7b0a4a6e62273b6ea6861e815459a7eeb41992 Mon Sep 17 00:00:00 2001 From: Chris Vest Date: Sun, 9 Jun 2024 09:42:13 -0700 Subject: [PATCH] Make PoolIT test less flaky High sleep time in the test thread could cause the background allocation thread to run ahead and increase the allocation counter too much. --- src/test/java/blackbox/slow/PoolIT.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/test/java/blackbox/slow/PoolIT.java b/src/test/java/blackbox/slow/PoolIT.java index d9791f66..6b43d710 100644 --- a/src/test/java/blackbox/slow/PoolIT.java +++ b/src/test/java/blackbox/slow/PoolIT.java @@ -290,7 +290,14 @@ void mustGraduallyReduceAggressivenessInRepairingFailingAllocator() throws Excep assertThrows(PoolException.class, () -> pool.claim(longTimeout).release()); long prev = 0, curr; for (int i = 0; i < 50; i++) { + long start = System.nanoTime(); Thread.sleep(100); + long elapsedMillis = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - start); + if (elapsedMillis >= 150) { + // Ignore outliers with very high sleep time. + i--; + continue; + } curr = counter.get(); long delta = curr - prev; prev = curr;