Welcome to the gateway team. This module is a fixed-window rate limiter: at most limit calls per window of window ticks, windows being [kwindow, (k+1)window). window_of works out which fixed window a time falls into; Fix…
Welcome to the gateway team. This module is a fixed-window rate limiter: at most limit calls per window of window ticks, windows being [k*window, (k+1)*window). window_of works out which fixed window a time falls into; FixedWindowLimiter.allow decides whether each call gets through.
There is one ticket below. Fix it within 35 minutes; it is graded by several hidden checks, each checked separately.
limit calls are allowed per fixed window.allow(now) returns True when permitted and False when the limit is exceeded.Clients are getting through slightly more often than they should. The limiter permits limit + 1 calls in a window because the count check is off by one.
allow(0) and allow(1) are True and allow(2) is False.[True, True, False, True]).(limit+1)-th call in a window is rejected.Keep the public class FixedWindowLimiter and its allow signature.
window.py (window_of) and limiter.py (FixedWindowLimiter and its allow method). The shipped regression tests are in tests/visible/; every one of them fails until the bug is fixed.pytest tests/visible.Adapted from treasure567/bloomberg-practice (round-1/onyx @ 8de07d5), used with the author's permission.
Visible test command
pytest tests/visibleThe repository’s own tests. Run all tests includes them, and so does every submission.
Repository
rate-limiter-allows-one-call-too-many
Changes under src/ are evaluated.