Loading case detail
A pull request adjusts the admission check of a fixed-window rate limiter. At the cap, one additional request is admitted instead of being refused.
--- a/app/limiter.py +++ b/app/limiter.py @@ -1,4 +1,4 @@ def allow(history: list[int], *, now: int, limit: int, window: int) -> bool: """Whether a request at ``now`` fits within ``limit`` requests per ``window`` seconds.""" recent = [stamp for stamp in history if stamp > now - window] - return len(recent) < limit + return len(recent) <= limit
pytest -q tests--- a/app/limiter.py +++ b/app/limiter.py @@ -1,4 +1,4 @@ def allow(history: list[int], *, now: int, limit: int, window: int) -> bool: """Whether a request at ``now`` fits within ``limit`` requests per ``window`` seconds.""" recent = [stamp for stamp in history if stamp > now - window] - return len(recent) <= limit + return len(recent) < limit