Skip to content

Commit 26cb1b2

Browse files
committed
fixed shouldResetCounterAfterWindow() test #2973
1 parent 3526c05 commit 26cb1b2

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

rate-limiting-pattern/src/test/java/com/iluwatar/rate/limiting/pattern/FixedWindowRateLimiterTest.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,18 @@ protected RateLimiter createRateLimiter(int limit, long windowMillis) {
1313

1414
@Test
1515
void shouldResetCounterAfterWindow() throws Exception {
16-
FixedWindowRateLimiter limiter = new FixedWindowRateLimiter(1, 1);
16+
FixedWindowRateLimiter limiter = new FixedWindowRateLimiter(1, 1); // 1 request per 1 second window
17+
18+
// First request should pass
1719
limiter.check("test", "op");
20+
21+
// Second request in same window should be throttled
1822
assertThrows(RateLimitException.class, () -> limiter.check("test", "op"));
1923

20-
TimeUnit.SECONDS.sleep(1);
24+
// Wait a bit more than 1 second to ensure window resets
25+
TimeUnit.MILLISECONDS.sleep(1100);
26+
27+
// After window reset, this should pass again
2128
limiter.check("test", "op");
2229
}
2330

0 commit comments

Comments
 (0)