boinkor-net / governor

A rate-limiting library for Rust (f.k.a. ratelimit_meter)
https://github.com/boinkor-net/governor
MIT License
592 stars 46 forks source link

Getting a free cell after clock advances #249

Open alpeb opened 2 weeks ago

alpeb commented 2 weeks ago

Hi, I'm wondering if this is expected behavior (and if so, what's the reasoning behind it) or a bug?

Here's a repro describing my issue:

#[test]
fn free_cell() {
    let clock = FakeRelativeClock::default();
    let rl = RateLimiter::direct_with_clock(Quota::per_second(nonzero!(5u32)), clock.clone());

    // consume the rate-limiter
    for _ in 1..=5 {
        assert!(rl.check().is_ok());
    }
    assert!(rl.check().is_err());

    // advance the clock
    clock.advance(Duration::from_secs(2));

    // Now I can get in one more extra cell
    for _ in 1..=6 {
        assert!(rl.check().is_ok());
    }

    assert!(rl.check().is_err());
}

Perhaps the same issue as #107?

Thanks!