(url, child, output, timeoutMs = 5_000)
| 427 | } |
| 428 | |
| 429 | async function waitForHTTPOK(url, child, output, timeoutMs = 5_000) { |
| 430 | const started = Date.now(); |
| 431 | |
| 432 | while (Date.now() - started < timeoutMs) { |
| 433 | if (child.exitCode !== null) { |
| 434 | throw new Error(`computerd exited before becoming ready: ${child.exitCode}\n${output()}`); |
| 435 | } |
| 436 | |
| 437 | try { |
| 438 | const response = await request(url); |
| 439 | if (response.statusCode === 200) return; |
| 440 | } catch (error) { |
| 441 | if (!isConnectionError(error)) throw error; |
| 442 | } |
| 443 | |
| 444 | await delay(50); |
| 445 | } |
| 446 | |
| 447 | throw new Error(`timed out waiting for ${url}\n${output()}`); |
| 448 | } |
| 449 | |
| 450 | function request(url) { |
| 451 | return new Promise((resolve, reject) => { |
no test coverage detected