Wait until the proxy is ready.
(timeout_s=60)
| 47 | |
| 48 | |
| 49 | async def wait_for_proxy(timeout_s=60): |
| 50 | """Wait until the proxy is ready.""" |
| 51 | url = f"http://127.0.0.1:{PROXY_PORT}/docs" |
| 52 | start = time.monotonic() |
| 53 | while True: |
| 54 | try: |
| 55 | async with httpx.AsyncClient(timeout=3.0) as client: |
| 56 | resp = await client.get(url) |
| 57 | if resp.status_code < 500: |
| 58 | logger.info("Proxy ready (status=%d)", resp.status_code) |
| 59 | return |
| 60 | except Exception: |
| 61 | pass |
| 62 | if time.monotonic() - start > timeout_s: |
| 63 | raise TimeoutError("Proxy did not start in time") |
| 64 | await asyncio.sleep(1.0) |
| 65 | |
| 66 | |
| 67 | async def send_chat(messages, session_id="test_session_001", session_done=False): |