From 946809f47c7bb8de06b75f22bdd1d0b0b01ed4ac Mon Sep 17 00:00:00 2001 From: Will Miao Date: Mon, 12 Oct 2026 11:51:48 +0800 Subject: [PATCH] test(rate-limit): tolerate the timer on Windows, and restore two bounds The last Windows failure was float noise on an upper bound: a 0.15s cooldown window reports 0.15000000000000568 remaining, so the assertion missed by 6e-15. The upper bound now carries an epsilon. The two `elapsed >= 0.14` cooldown assertions had been weakened to `>= 0.09` by a substring replace while relaxing the pacing bound -- that would have let a missing wait pass. They are back at 0.12 (0.15s minus Windows timer rounding), which still fails if the cooldown is not awaited. --- tests/services/test_rate_limit_coordinator.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/services/test_rate_limit_coordinator.py b/tests/services/test_rate_limit_coordinator.py index 5e429ae5..a889c2be 100644 --- a/tests/services/test_rate_limit_coordinator.py +++ b/tests/services/test_rate_limit_coordinator.py @@ -84,12 +84,15 @@ async def test_register_rate_limit_arms_cooldown_and_waits(monkeypatch): ) coordinator.register_rate_limit("example.com", retry_after=0.15) assert coordinator.in_cooldown("example.com") - assert 0.1 < coordinator.remaining_seconds("example.com") <= 0.15 + remaining = coordinator.remaining_seconds("example.com") + # The upper bound only says "barely any time has passed": allow the timer's + # float noise (Windows reports 0.15000000000000568 for a 0.15s window). + assert 0.1 < remaining <= 0.15 + 1e-6 start = time.monotonic() await coordinator.wait_for_slot("example.com") elapsed = time.monotonic() - start - assert elapsed >= 0.09 # Windows timer granularity rounds 0.1s down4 + assert elapsed >= 0.12 # 0.15s cooldown, minus Windows timer rounding assert not coordinator.in_cooldown("example.com") @@ -255,7 +258,7 @@ async def test_make_request_paces_consecutive_calls(monkeypatch): await downloader.make_request("GET", "https://api.example.com/a") await downloader.make_request("GET", "https://api.example.com/b") elapsed = time.monotonic() - start - assert elapsed >= 0.09 # Windows timer granularity rounds 0.1s down4 + assert elapsed >= 0.12 # 0.15s cooldown, minus Windows timer rounding async def test_make_request_gate_disabled_returns_429_immediately(monkeypatch):