From 0817ff7b1cfba5c7add5abf5dcbbe1cf89066336 Mon Sep 17 00:00:00 2001 From: Min Jin Date: Mon, 25 Sep 2023 18:14:51 -0700 Subject: [PATCH] fixing flaky rate-limiting test Signed-off-by: Min Jin --- .../extended/workqueue/DefaultRateLimitQueueTest.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/extended/src/test/java/io/kubernetes/client/extended/workqueue/DefaultRateLimitQueueTest.java b/extended/src/test/java/io/kubernetes/client/extended/workqueue/DefaultRateLimitQueueTest.java index 237711c9b4..d4ee2600c4 100644 --- a/extended/src/test/java/io/kubernetes/client/extended/workqueue/DefaultRateLimitQueueTest.java +++ b/extended/src/test/java/io/kubernetes/client/extended/workqueue/DefaultRateLimitQueueTest.java @@ -53,9 +53,12 @@ public void testSimpleRateLimitQueue() throws Exception { long t1 = System.nanoTime(); rlq.addRateLimited("foo"); rlq.get(); - long t2 = System.nanoTime(); + long t2 = System.nanoTime() - 100000; + long elapsed = t2-t1; + long elapsedMillis = Math.round((float) elapsed / 1000_000f); + long backoffMillis = Math.round((float) MockRateLimiter.mockConstantBackoff.toNanos() / 1000_000f); assertTrue( - "Unexpected time: " + (t2 - t1) + " vs " + MockRateLimiter.mockConstantBackoff.toNanos(), - t2 - t1 >= MockRateLimiter.mockConstantBackoff.toNanos()); + "Unexpected time: " + elapsedMillis + " vs " + backoffMillis, + elapsedMillis >= backoffMillis); } }