(url: string, timeoutMs = 120_000)
| 84 | * Requiring consecutive successes avoids returning during a brief up-blip while |
| 85 | * a freshly-installed/just-upgraded stack's nginx upstream is still flapping. */ |
| 86 | export async function waitForUrl(url: string, timeoutMs = 120_000): Promise<boolean> { |
| 87 | const deadline = Date.now() + timeoutMs |
| 88 | let consecutive = 0 |
| 89 | while (Date.now() < deadline) { |
| 90 | try { |
| 91 | const res = await fetch(url, { signal: AbortSignal.timeout(4000) }) |
| 92 | if (res.ok) { |
| 93 | if (++consecutive >= 2) return true |
| 94 | await new Promise((r) => setTimeout(r, 750)) // confirm stability quickly |
| 95 | continue |
| 96 | } |
| 97 | consecutive = 0 // a non-2xx (e.g. 502) resets the streak |
| 98 | } catch { consecutive = 0 /* not ready */ } |
| 99 | await new Promise((r) => setTimeout(r, 1500)) |
| 100 | } |
| 101 | return false |
| 102 | } |
| 103 | |
| 104 | /** Polls the org seed endpoint */ |
| 105 | export async function waitForOrgSeed(port: number, orgSlug = 'default', timeoutMs = 60_000): Promise<boolean> { |
no test coverage detected