[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>
This commit is contained in:
co-authored by
Wentao Ye
parent
789c4f905e
commit
ea3115e30b
@@ -483,20 +483,32 @@ async def _await_supervisor_health(
|
|||||||
|
|
||||||
|
|
||||||
async def _poll_until_api_server_running(
|
async def _poll_until_api_server_running(
|
||||||
port: int, retries: int = 10, use_ssl: bool = False
|
port: int, timeout_s: float = 30.0, use_ssl: bool = False
|
||||||
) -> None:
|
) -> None:
|
||||||
|
"""Return once the child accepts a request; it reports 503 until healthy."""
|
||||||
scheme = "https" if use_ssl else "http"
|
scheme = "https" if use_ssl else "http"
|
||||||
url = f"{scheme}://127.0.0.1:{port}/health"
|
url = f"{scheme}://127.0.0.1:{port}/health"
|
||||||
|
deadline = time.monotonic() + timeout_s
|
||||||
|
last_exc: Exception | None = None
|
||||||
async with aiohttp.ClientSession() as session:
|
async with aiohttp.ClientSession() as session:
|
||||||
for _ in range(retries):
|
while (remaining_s := deadline - time.monotonic()) > 0:
|
||||||
try:
|
try:
|
||||||
async with session.get(url, ssl=False if use_ssl else None) as resp:
|
request_timeout = aiohttp.ClientTimeout(total=min(2.0, remaining_s))
|
||||||
if resp.status != 200:
|
async with session.get(
|
||||||
return
|
url,
|
||||||
await asyncio.sleep(1.0)
|
ssl=False if use_ssl else None,
|
||||||
except aiohttp.ClientError:
|
timeout=request_timeout,
|
||||||
|
):
|
||||||
|
return
|
||||||
|
except (aiohttp.ClientError, asyncio.TimeoutError) as exc:
|
||||||
|
last_exc = exc
|
||||||
print("Test detected not started yet, sleeping for 1s")
|
print("Test detected not started yet, sleeping for 1s")
|
||||||
await asyncio.sleep(1.0)
|
remaining_s = deadline - time.monotonic()
|
||||||
|
if remaining_s > 0:
|
||||||
|
await asyncio.sleep(min(1.0, remaining_s))
|
||||||
|
raise TimeoutError(
|
||||||
|
f"API server on port {port} did not start within {timeout_s}s"
|
||||||
|
) from last_exc
|
||||||
|
|
||||||
|
|
||||||
async def _set_healthy(port: int, use_ssl: bool = False) -> None:
|
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:
|
|||||||
session.get(url, ssl=False if use_ssl else None) as resp,
|
session.get(url, ssl=False if use_ssl else None) as resp,
|
||||||
):
|
):
|
||||||
assert resp.status != 200
|
assert resp.status != 200
|
||||||
except Exception as e:
|
except aiohttp.ClientConnectionError:
|
||||||
assert isinstance(e, aiohttp.ClientConnectorError)
|
return
|
||||||
|
|
||||||
|
|
||||||
@contextlib.asynccontextmanager
|
@contextlib.asynccontextmanager
|
||||||
|
|||||||
Reference in New Issue
Block a user