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).
This commit is contained in:
Marcelo Trylesinski 2026-02-15 19:12:48 +01:00
parent c22ed477eb
commit e1b6fa48f7
2 changed files with 7 additions and 2 deletions

View File

@ -84,7 +84,11 @@ def test_multiprocess_health_check() -> None:
process = supervisor.processes[0]
process.kill()
assert not process.is_alive()
time.sleep(1)
deadline = time.monotonic() + 10
while time.monotonic() < deadline:
if all(p.is_alive() for p in supervisor.processes):
break
time.sleep(0.1)
for p in supervisor.processes:
assert p.is_alive()
supervisor.signal_queue.append(signal.SIGINT)

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: