chore(e2e): reduce verbose logging in pretest health checks
This commit is contained in:
parent
8b4e054023
commit
a5a45d1967
1 changed files with 6 additions and 13 deletions
|
|
@ -57,23 +57,18 @@ 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] Waiting for ${healthURL} to become healthy...`);
|
||||||
const startedAt = Date.now();
|
const startedAt = Date.now();
|
||||||
let attempt = 0;
|
let attempt = 0;
|
||||||
|
|
||||||
const checkHealth = () => {
|
const checkHealth = () => {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
const req = http.get(healthURL, (res) => {
|
const req = http.get(healthURL, (res) => {
|
||||||
console.log(`[pretest] HTTP response status: ${res.statusCode}`);
|
|
||||||
res.resume(); // Consume response data to free up memory
|
res.resume(); // Consume response data to free up memory
|
||||||
resolve(res.statusCode >= 200 && res.statusCode < 300);
|
resolve(res.statusCode >= 200 && res.statusCode < 300);
|
||||||
});
|
});
|
||||||
req.on('error', (err) => {
|
req.on('error', () => resolve(false));
|
||||||
console.log(`[pretest] HTTP error: ${err.code || err.message}`);
|
|
||||||
resolve(false);
|
|
||||||
});
|
|
||||||
req.setTimeout(5000, () => {
|
req.setTimeout(5000, () => {
|
||||||
console.log(`[pretest] HTTP timeout`);
|
|
||||||
req.destroy();
|
req.destroy();
|
||||||
resolve(false);
|
resolve(false);
|
||||||
});
|
});
|
||||||
|
|
@ -82,20 +77,18 @@ const waitForHealth = async (healthURL, timeoutMs = 120_000) => {
|
||||||
|
|
||||||
while (Date.now() - startedAt < timeoutMs) {
|
while (Date.now() - startedAt < timeoutMs) {
|
||||||
attempt++;
|
attempt++;
|
||||||
console.log(`[pretest] Health check attempt ${attempt}...`);
|
|
||||||
try {
|
try {
|
||||||
const ok = await checkHealth();
|
const ok = await checkHealth();
|
||||||
if (ok) {
|
if (ok) {
|
||||||
console.log(`[pretest] Health check succeeded!`);
|
console.log(`[pretest] Health check passed after ${attempt} attempts`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch {
|
||||||
console.log(`[pretest] Unexpected error: ${error.message}`);
|
// ignore and retry
|
||||||
}
|
}
|
||||||
console.log(`[pretest] Sleeping 1s before retry...`);
|
|
||||||
await new Promise((r) => setTimeout(r, 1000));
|
await new Promise((r) => setTimeout(r, 1000));
|
||||||
}
|
}
|
||||||
throw new Error(`Timed out waiting for ${healthURL}`);
|
throw new Error(`Timed out waiting for ${healthURL} after ${attempt} attempts`);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue