Compare commits

..

No commits in common. "4b4e55dbe276a101b092fcee792376a44dea10e8" and "73017c1a30611ab9f205460c23353e67b894317b" have entirely different histories.

View File

@ -419,12 +419,11 @@ 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()
assert release.wait(1) time.sleep(0.2)
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)
@ -433,16 +432,15 @@ 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