(origin: string, timeoutMs: number)
| 149 | |
| 150 | /** Single probe of `/api/v1/healthz`. Returns true if the response envelope reports `code: 0`. */ |
| 151 | export async function isServerHealthy(origin: string, timeoutMs: number): Promise<boolean> { |
| 152 | const controller = new AbortController(); |
| 153 | const timeout = setTimeout(() => { |
| 154 | controller.abort(); |
| 155 | }, timeoutMs); |
| 156 | try { |
| 157 | const response = await fetch(`${origin}/api/v1/healthz`, { |
| 158 | signal: controller.signal, |
| 159 | }); |
| 160 | if (!response.ok) return false; |
| 161 | const body = (await response.json()) as { code?: unknown }; |
| 162 | return body.code === 0; |
| 163 | } catch { |
| 164 | return false; |
| 165 | } finally { |
| 166 | clearTimeout(timeout); |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | /** Poll `/api/v1/healthz` until it reports healthy or `timeoutMs` elapses. */ |
| 171 | export async function waitForServerHealthy(origin: string, timeoutMs: number): Promise<boolean> { |
no test coverage detected