Skip to content

Commit 8dc4059

Browse files
committed
Update UUID test to include mixture of clock advance duration
1 parent 715f181 commit 8dc4059

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

exercises/practice/rate-limiter/src/test/java/RateLimiterTest.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,19 +127,21 @@ void exactBoundaryIsNewWindowEveryTime() {
127127
@Test
128128
void supportsUuidKeys() {
129129
TimeSource clock = new TimeSource(Instant.EPOCH);
130-
RateLimiter<UUID> limiter = new RateLimiter<>(1, Duration.ofNanos(100L), clock);
130+
// Use a seconds-long window and advance in smaller units to mix Duration usage
131+
RateLimiter<UUID> limiter = new RateLimiter<>(1, Duration.ofSeconds(1L), clock);
131132

132133
UUID a = UUID.fromString("00000000-0000-0000-0000-000000000001");
133134
UUID b = UUID.fromString("00000000-0000-0000-0000-000000000002");
134135

135136
assertThat(limiter.allow(a)).isTrue();
136137
assertThat(limiter.allow(a)).isFalse();
137138
// Advance slightly so the second client's window anchors later
138-
clock.advance(Duration.ofNanos(1L));
139+
clock.advance(Duration.ofMillis(1L));
139140
assertThat(limiter.allow(b)).isTrue();
140141
assertThat(limiter.allow(b)).isFalse();
141142

142-
clock.advance(Duration.ofNanos(100L));
143+
// Advance exactly one second to hit the window boundary
144+
clock.advance(Duration.ofSeconds(1L));
143145
assertThat(limiter.allow(a)).isTrue();
144146
assertThat(limiter.allow(b)).isTrue();
145147
}

0 commit comments

Comments
 (0)