From 7d13b0109089c86666687797ef33ac50f735a541 Mon Sep 17 00:00:00 2001 From: Vipin Sharma Date: Sun, 24 Oct 2021 01:27:11 +0530 Subject: [PATCH] [fix] avoided thread.sleep usage and added semaphore as replacement Committer: Vipin Sharma --- .../workqueue/ratelimiter/BucketRateLimiterTest.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/extended/src/test/java/io/kubernetes/client/extended/workqueue/ratelimiter/BucketRateLimiterTest.java b/extended/src/test/java/io/kubernetes/client/extended/workqueue/ratelimiter/BucketRateLimiterTest.java index 8baa294546..8dd7397531 100644 --- a/extended/src/test/java/io/kubernetes/client/extended/workqueue/ratelimiter/BucketRateLimiterTest.java +++ b/extended/src/test/java/io/kubernetes/client/extended/workqueue/ratelimiter/BucketRateLimiterTest.java @@ -16,10 +16,14 @@ import static org.junit.Assert.assertTrue; import java.time.Duration; +import java.util.concurrent.TimeUnit; + import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; +import org.apache.commons.lang3.concurrent.TimedSemaphore; + public class BucketRateLimiterTest { @Rule public ExpectedException thrown = ExpectedException.none(); @@ -46,15 +50,16 @@ public void testBucketRateLimiterBasic() { @Test public void testBucketRateLimiterTokenAdded() throws InterruptedException { RateLimiter rateLimiter = new BucketRateLimiter<>(2, 1, Duration.ofSeconds(2)); + TimedSemaphore timedSemaphore = new TimedSemaphore(4, TimeUnit.SECONDS, 1); + timedSemaphore.acquire(); assertEquals(Duration.ZERO, rateLimiter.when("one")); assertEquals(Duration.ZERO, rateLimiter.when("one")); Duration waitDuration = rateLimiter.when("one"); assertTrue(waitDuration.getSeconds() > 0); - Thread.sleep(4000); - + timedSemaphore.acquire(); assertEquals(Duration.ZERO, rateLimiter.when("two")); waitDuration = rateLimiter.when("two");