From 8f92286cced52bfcb2747801e6c716694b0cd4d6 Mon Sep 17 00:00:00 2001 From: timmy Date: Sat, 15 Aug 2026 10:13:05 +0000 Subject: [PATCH] test: make event-loop release gate deterministic (Closes #884) --- tests/test_dashboard_auth.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/tests/test_dashboard_auth.py b/tests/test_dashboard_auth.py index 5206462..b4537ee 100644 --- a/tests/test_dashboard_auth.py +++ b/tests/test_dashboard_auth.py @@ -1860,9 +1860,14 @@ async def test_session_registry_latency_does_not_block_the_event_loop(access_con async def test_sign_in_throttle_lookup_does_not_block_the_event_loop( access_control, monkeypatch ): + lookup_started = threading.Event() + lookup_finished = threading.Event() + class SlowAttempts: def retry_after(self, source): - time.sleep(0.15) + lookup_started.set() + time.sleep(0.3) + lookup_finished.set() return 17 def record_blocked(self, *, method): @@ -1874,15 +1879,13 @@ async def test_sign_in_throttle_lookup_does_not_block_the_event_loop( sign_in = asyncio.create_task( client.post("/api/v1/session", json={"access_token": "wrong"}) ) - await asyncio.sleep(0) - started = time.perf_counter() + assert await asyncio.to_thread(lookup_started.wait, 1) await asyncio.sleep(0.01) - heartbeat_elapsed = time.perf_counter() - started + assert not lookup_finished.is_set() response = await sign_in assert response.status_code == 429 assert response.headers["retry-after"] == "17" - assert heartbeat_elapsed < 0.08 @pytest.mark.anyio -- 2.43.0