Poll for readiness in test_multiprocess_health_check and run_server (#2816)

* Poll for readiness in `test_multiprocess_health_check` and `run_server`

Apply the same polling pattern to `test_multiprocess_health_check` — wait
for all processes to be alive instead of a fixed 1s sleep.

In `run_server`, wait for `server.started` instead of a fixed 0.1s sleep
to avoid connection races on slow setups (e.g. free-threaded Python 3.14).

* Avoid uncovered branch in health check polling loop

* Add pragma: no cover to health check polling loop body
This commit is contained in:
Marcelo Trylesinski 2026-02-15 19:23:26 +01:00 committed by GitHub
parent 7e9ce2c974
commit 0779f7f8a4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 4 deletions

View File

@ -84,9 +84,10 @@ def test_multiprocess_health_check() -> None:
process = supervisor.processes[0]
process.kill()
assert not process.is_alive()
time.sleep(1)
for p in supervisor.processes:
assert p.is_alive()
deadline = time.monotonic() + 10
while not all(p.is_alive() for p in supervisor.processes): # pragma: no cover
assert time.monotonic() < deadline, "Timed out waiting for processes to be alive"
time.sleep(0.1)
supervisor.signal_queue.append(signal.SIGINT)
supervisor.join_all()

View File

@ -16,7 +16,8 @@ from uvicorn import Config, Server
async def run_server(config: Config, sockets: list[socket] | None = None) -> AsyncIterator[Server]:
server = Server(config=config)
task = asyncio.create_task(server.serve(sockets=sockets))
await asyncio.sleep(0.1)
while not server.started:
await asyncio.sleep(0.05)
try:
yield server
finally: