(url, timeoutMs = DEFAULT_WAIT_TIMEOUT_MS)
| 78 | } |
| 79 | |
| 80 | async function waitForServer(url, timeoutMs = DEFAULT_WAIT_TIMEOUT_MS) { |
| 81 | const startedAt = Date.now(); |
| 82 | |
| 83 | while (Date.now() - startedAt < timeoutMs) { |
| 84 | try { |
| 85 | const response = await fetch(url); |
| 86 | if (response.ok) { |
| 87 | return; |
| 88 | } |
| 89 | } catch { |
| 90 | // Keep polling until timeout. |
| 91 | } |
| 92 | |
| 93 | await delay(500); |
| 94 | } |
| 95 | |
| 96 | throw new Error(`Timed out waiting for agent-server at ${url}`); |
| 97 | } |
| 98 | |
| 99 | function spawnProcess(command, args, options = {}) { |
| 100 | const child = spawn( |