Skip to content

Commit 29ee227

Browse files
acatangiuandreeaflorescu
authored andcommitted
Change rate limiter test that sporadically fails on slow machines
Change a test where the bucket would completely refill 1000 tokens in just 1ms that fails on slow machines when run under kcov, where the rate at which the tokenbucket refills is faster than it takes the instrumented code to validate. Signed-off-by: Adrian Catangiu <[email protected]>
1 parent 6dbe5db commit 29ee227

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

fc_util/src/ratelimiter/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -363,16 +363,16 @@ mod tests {
363363

364364
#[test]
365365
fn test_token_bucket_reduce() {
366-
// token bucket with capacity 1000 and refill time of 1 millisecond
366+
// token bucket with capacity 1000 and refill time of 1000 milliseconds
367+
// allowing rate of 1 token/ms
367368
let capacity = 1000;
368-
let refill_ms = 1;
369-
let refill_duration = Duration::from_millis(refill_ms);
369+
let refill_ms = 1000;
370370
let mut tb = TokenBucket::new(capacity, refill_ms as u64);
371371

372372
assert!(tb.reduce(123));
373373
assert_eq!(tb.get_current_budget(), capacity - 123);
374374

375-
thread::sleep(refill_duration);
375+
thread::sleep(Duration::from_millis(123));
376376
assert!(tb.reduce(1));
377377
assert_eq!(tb.get_current_budget(), capacity - 1);
378378
assert!(tb.reduce(100));

0 commit comments

Comments
 (0)