(port, timeoutMs = HEALTH_TIMEOUT_MS)
| 153 | } |
| 154 | |
| 155 | async function waitForHealth(port, timeoutMs = HEALTH_TIMEOUT_MS) { |
| 156 | const url = `http://127.0.0.1:${port}/health`; |
| 157 | const deadline = Date.now() + timeoutMs; |
| 158 | while (Date.now() < deadline) { |
| 159 | try { |
| 160 | const resp = await fetch(url, { signal: AbortSignal.timeout(2000) }); |
| 161 | if (resp.ok) return true; |
| 162 | } catch { /* not ready */ } |
| 163 | await sleep(HEALTH_POLL_MS); |
| 164 | } |
| 165 | return false; |
| 166 | } |
| 167 | |
| 168 | async function fetchJson(url) { |
| 169 | try { |