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.
This commit is contained in:
parent
75c8422b69
commit
8b4e054023
1 changed files with 25 additions and 6 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
import { spawn } from 'node:child_process';
|
import { spawn } from 'node:child_process';
|
||||||
|
import http from 'node:http';
|
||||||
|
|
||||||
// Add signal handlers to debug unexpected termination
|
// Add signal handlers to debug unexpected termination
|
||||||
const signals = ['SIGTERM', 'SIGINT', 'SIGHUP', 'SIGPIPE', 'SIGQUIT'];
|
const signals = ['SIGTERM', 'SIGINT', 'SIGHUP', 'SIGPIPE', 'SIGQUIT'];
|
||||||
|
|
@ -54,24 +55,42 @@ const canRun = async (command, args) => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
const waitForHealth = async (healthURL, timeoutMs = 120_000) => {
|
const waitForHealth = async (healthURL, timeoutMs = 120_000) => {
|
||||||
console.log(`[pretest] Starting health check loop for ${healthURL}`);
|
console.log(`[pretest] Starting health check loop for ${healthURL}`);
|
||||||
const startedAt = Date.now();
|
const startedAt = Date.now();
|
||||||
let attempt = 0;
|
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) {
|
while (Date.now() - startedAt < timeoutMs) {
|
||||||
attempt++;
|
attempt++;
|
||||||
console.log(`[pretest] Health check attempt ${attempt}...`);
|
console.log(`[pretest] Health check attempt ${attempt}...`);
|
||||||
try {
|
try {
|
||||||
console.log(`[pretest] Calling fetch...`);
|
const ok = await checkHealth();
|
||||||
const res = await fetch(healthURL, { method: 'GET' });
|
if (ok) {
|
||||||
console.log(`[pretest] Fetch returned status ${res.status}`);
|
|
||||||
if (res.ok) {
|
|
||||||
console.log(`[pretest] Health check succeeded!`);
|
console.log(`[pretest] Health check succeeded!`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(`[pretest] Fetch error: ${error.code || error.message}`);
|
console.log(`[pretest] Unexpected error: ${error.message}`);
|
||||||
// ignore and retry
|
|
||||||
}
|
}
|
||||||
console.log(`[pretest] Sleeping 1s before retry...`);
|
console.log(`[pretest] Sleeping 1s before retry...`);
|
||||||
await new Promise((r) => setTimeout(r, 1000));
|
await new Promise((r) => setTimeout(r, 1000));
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue