Stabilize the event-loop release gate #886

Merged
timmy merged 1 commits from timmy/884-stabilize-release-gate into main 2026-08-15 10:16:39 +00:00

View File

@ -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( async def test_sign_in_throttle_lookup_does_not_block_the_event_loop(
access_control, monkeypatch access_control, monkeypatch
): ):
lookup_started = threading.Event()
lookup_finished = threading.Event()
class SlowAttempts: class SlowAttempts:
def retry_after(self, source): def retry_after(self, source):
time.sleep(0.15) lookup_started.set()
time.sleep(0.3)
lookup_finished.set()
return 17 return 17
def record_blocked(self, *, method): 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( sign_in = asyncio.create_task(
client.post("/api/v1/session", json={"access_token": "wrong"}) client.post("/api/v1/session", json={"access_token": "wrong"})
) )
await asyncio.sleep(0) assert await asyncio.to_thread(lookup_started.wait, 1)
started = time.perf_counter()
await asyncio.sleep(0.01) await asyncio.sleep(0.01)
heartbeat_elapsed = time.perf_counter() - started assert not lookup_finished.is_set()
response = await sign_in response = await sign_in
assert response.status_code == 429 assert response.status_code == 429
assert response.headers["retry-after"] == "17" assert response.headers["retry-after"] == "17"
assert heartbeat_elapsed < 0.08
@pytest.mark.anyio @pytest.mark.anyio