test: make health timing gate deterministic (Closes #1289)
This commit is contained in:
parent
73017c1a30
commit
fe1049ee99
|
|
@ -419,11 +419,12 @@ async def test_slow_ledger_completion_does_not_block_health_requests(monkeypatch
|
||||||
return {"id": 249, "body": body}
|
return {"id": 249, "body": body}
|
||||||
|
|
||||||
started = threading.Event()
|
started = threading.Event()
|
||||||
|
release = threading.Event()
|
||||||
original_complete = main._idempotency_ledger.complete
|
original_complete = main._idempotency_ledger.complete
|
||||||
|
|
||||||
def slow_complete(key, response):
|
def slow_complete(key, response):
|
||||||
started.set()
|
started.set()
|
||||||
time.sleep(0.2)
|
assert release.wait(1)
|
||||||
return original_complete(key, response)
|
return original_complete(key, response)
|
||||||
|
|
||||||
monkeypatch.setattr(main._idempotency_ledger, "complete", slow_complete)
|
monkeypatch.setattr(main._idempotency_ledger, "complete", slow_complete)
|
||||||
|
|
@ -432,15 +433,16 @@ async def test_slow_ledger_completion_does_not_block_health_requests(monkeypatch
|
||||||
transport = httpx.ASGITransport(app=main.app)
|
transport = httpx.ASGITransport(app=main.app)
|
||||||
|
|
||||||
async with httpx.AsyncClient(transport=transport, base_url="http://test") as client:
|
async with httpx.AsyncClient(transport=transport, base_url="http://test") as client:
|
||||||
started_at = asyncio.get_running_loop().time()
|
|
||||||
authored = asyncio.create_task(client.post(
|
authored = asyncio.create_task(client.post(
|
||||||
"/api/v1/repos/stackchain/api/issues/248/comments",
|
"/api/v1/repos/stackchain/api/issues/248/comments",
|
||||||
json={"body": "Persist without freezing"},
|
json={"body": "Persist without freezing"},
|
||||||
headers={"Idempotency-Key": "slow-completion-248"},
|
headers={"Idempotency-Key": "slow-completion-248"},
|
||||||
))
|
))
|
||||||
assert await asyncio.to_thread(started.wait, 1)
|
assert await asyncio.to_thread(started.wait, 1)
|
||||||
|
started_at = asyncio.get_running_loop().time()
|
||||||
health = await client.get("/healthz")
|
health = await client.get("/healthz")
|
||||||
health_elapsed = asyncio.get_running_loop().time() - started_at
|
health_elapsed = asyncio.get_running_loop().time() - started_at
|
||||||
|
release.set()
|
||||||
authored_response = await authored
|
authored_response = await authored
|
||||||
|
|
||||||
assert health.status_code == 200
|
assert health.status_code == 200
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user