Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting a free cell after clock advances #249

Open
alpeb opened this issue Nov 5, 2024 · 0 comments
Open

Getting a free cell after clock advances #249

alpeb opened this issue Nov 5, 2024 · 0 comments

Comments

@alpeb
Copy link

alpeb commented Nov 5, 2024

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:

  • Set a direct rate-limiter with a max_burst of 5
  • Consume that quota and verify another cell is not allowed
  • Advance time a couple of seconds
  • Now 6 cells are allowed?
#[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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant