test: make event-loop release gate deterministic (Closes #884)
This commit is contained in:
parent
27be5d43a2
commit
8f92286cce
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user