[CI] Stabilize DP supervisor lifecycle tests (#51557)

Signed-off-by: Taneem Ibrahim <taneem.ibrahim@gmail.com> Co-authored-by: Wentao Ye <44945378+yewentao256@users.noreply.github.com>

Taneem Ibrahim committed Aug 10, 2026 at 15:13 UTC ea3115e30b1288e3e3ecafd3943695d3f06d1eac
1 file changed +22 -10
tests/entrypoints/openai/test_dp_supervisor.py
+22 -10
@@ -483,20 +483,32 @@ async def _await_supervisor_health(
483
484
485 async def _poll_until_api_server_running(
486 - port: int, retries: int = 10, use_ssl: bool = False
486 + port: int, timeout_s: float = 30.0, use_ssl: bool = False
487 ) -> None:
488 + """Return once the child accepts a request; it reports 503 until healthy."""
489 scheme = "https" if use_ssl else "http"
490 url = f"{scheme}://127.0.0.1:{port}/health"
491 + deadline = time.monotonic() + timeout_s
492 + last_exc: Exception | None = None
493 async with aiohttp.ClientSession() as session:
491 - for _ in range(retries):
494 + while (remaining_s := deadline - time.monotonic()) > 0:
495 try:
493 - async with session.get(url, ssl=False if use_ssl else None) as resp:
494 - if resp.status != 200:
495 - return
496 - await asyncio.sleep(1.0)
497 - except aiohttp.ClientError:
496 + request_timeout = aiohttp.ClientTimeout(total=min(2.0, remaining_s))
497 + async with session.get(
498 + url,
499 + ssl=False if use_ssl else None,
500 + timeout=request_timeout,
501 + ):
502 + return
503 + except (aiohttp.ClientError, asyncio.TimeoutError) as exc:
504 + last_exc = exc
505 print("Test detected not started yet, sleeping for 1s")
499 - await asyncio.sleep(1.0)
506 + remaining_s = deadline - time.monotonic()
507 + if remaining_s > 0:
508 + await asyncio.sleep(min(1.0, remaining_s))
509 + raise TimeoutError(
510 + f"API server on port {port} did not start within {timeout_s}s"
511 + ) from last_exc
512
513
514 async def _set_healthy(port: int, use_ssl: bool = False) -> None:
@@ -528,8 +540,8 @@ async def _kill_server(port: int, use_ssl: bool = False) -> None:
540 session.get(url, ssl=False if use_ssl else None) as resp,
541 ):
542 assert resp.status != 200
531 - except Exception as e:
532 - assert isinstance(e, aiohttp.ClientConnectorError)
543 + except aiohttp.ClientConnectionError:
544 + return
545
546
547 @contextlib.asynccontextmanager