Compare commits

...

2 Commits

Author SHA1 Message Date
Marcelo Trylesinski
e1b6fa48f7 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).
2026-02-15 19:12:48 +01:00
Marcelo Trylesinski
c22ed477eb Poll for PID changes in test_multiprocess_sighup instead of fixed sleep
The 1-second sleep wasn't always enough for the supervisor to pick up the
signal and complete `restart_all()`, causing flaky failures on macOS 3.14.
2026-02-15 18:54:03 +01:00
2 changed files with 14 additions and 3 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)
@ -129,7 +133,13 @@ def test_multiprocess_sighup() -> None:
time.sleep(1)
pids = [p.pid for p in supervisor.processes]
supervisor.signal_queue.append(signal.SIGHUP)
time.sleep(1)
# Poll instead of a fixed sleep — the supervisor loop runs on a 0.5s interval and `restart_all()` terminates/joins
# each worker sequentially, so the total time is non-deterministic.
deadline = time.monotonic() + 10
while time.monotonic() < deadline:
if [p.pid for p in supervisor.processes] != pids:
break
time.sleep(0.1)
assert pids != [p.pid for p in supervisor.processes]
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: