From 8b4e054023563e3cb07cbf25a689ad574b25ad66 Mon Sep 17 00:00:00 2001 From: rcourtman Date: Fri, 19 Dec 2025 16:11:57 +0000 Subject: [PATCH] fix(e2e): use http module instead of fetch for health checks Exit code 13 in Node.js indicates 'Unfinished Top-Level Await'. Replacing fetch with native http module to see if this resolves the issue. --- tests/integration/scripts/pretest.mjs | 31 +++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/tests/integration/scripts/pretest.mjs b/tests/integration/scripts/pretest.mjs index b60dfd3..8e634cd 100644 --- a/tests/integration/scripts/pretest.mjs +++ b/tests/integration/scripts/pretest.mjs @@ -1,4 +1,5 @@ import { spawn } from 'node:child_process'; +import http from 'node:http'; // Add signal handlers to debug unexpected termination const signals = ['SIGTERM', 'SIGINT', 'SIGHUP', 'SIGPIPE', 'SIGQUIT']; @@ -54,24 +55,42 @@ const canRun = async (command, args) => { } }; + const waitForHealth = async (healthURL, timeoutMs = 120_000) => { console.log(`[pretest] Starting health check loop for ${healthURL}`); const startedAt = Date.now(); let attempt = 0; + + const checkHealth = () => { + return new Promise((resolve) => { + const req = http.get(healthURL, (res) => { + console.log(`[pretest] HTTP response status: ${res.statusCode}`); + res.resume(); // Consume response data to free up memory + resolve(res.statusCode >= 200 && res.statusCode < 300); + }); + req.on('error', (err) => { + console.log(`[pretest] HTTP error: ${err.code || err.message}`); + resolve(false); + }); + req.setTimeout(5000, () => { + console.log(`[pretest] HTTP timeout`); + req.destroy(); + resolve(false); + }); + }); + }; + while (Date.now() - startedAt < timeoutMs) { attempt++; console.log(`[pretest] Health check attempt ${attempt}...`); try { - console.log(`[pretest] Calling fetch...`); - const res = await fetch(healthURL, { method: 'GET' }); - console.log(`[pretest] Fetch returned status ${res.status}`); - if (res.ok) { + const ok = await checkHealth(); + if (ok) { console.log(`[pretest] Health check succeeded!`); return; } } catch (error) { - console.log(`[pretest] Fetch error: ${error.code || error.message}`); - // ignore and retry + console.log(`[pretest] Unexpected error: ${error.message}`); } console.log(`[pretest] Sleeping 1s before retry...`); await new Promise((r) => setTimeout(r, 1000));