Integration tests: wait for a worker's WebSocket, not just its heartbeat
CI / Security (npm audit) (push) Successful in 21s
CI / Test (jest) (push) Successful in 23s
CI / Scan (secrets, workflows, shell) (push) Successful in 14s
CI / Integration (api) (push) Successful in 1m58s
CI / Lint (eslint) (pull_request) Successful in 44s
CI / UI (playwright) (push) Successful in 3m9s
CI / Test (jest) (pull_request) Successful in 42s
CI / Security (npm audit) (pull_request) Successful in 30s
CI / Scan (secrets, workflows, shell) (pull_request) Successful in 11s
CI / Integration (api) (pull_request) Successful in 1m44s
CI / Lint (eslint) (push) Successful in 13s
CI / Deploy (push) Skipped
CI / Notify (push) Skipped
CI / UI (playwright) (pull_request) Successful in 1m45s
CI / Deploy (pull_request) Skipped
CI / Notify (pull_request) Skipped

Under load a new worker's first heartbeat marked it online before its
WebSocket had connected, so a test's first command was refused, and the
cleanup in finally then threw its own error and hid the real one.
startWorker now waits until the server accepts a probe command for the
worker, and cleanup never throws (offline status has its own test).
Reproduced 1 in 6 under UI-test load before; 0 in 10 after.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
jaredandClaude Opus 5.5 committed 2026-11-22 15:54:38 -05:00
1 parent 394665e88a
commit 67a9e1c009
1 file changed
+13 -2
+13 -2
View File
@@ -74,10 +74,18 @@ async function startWorker(name, env = {}) {
let log = '';
child.stdout.on('data', d => { log += d; });
child.stderr.on('data', d => { log += d; });
const fail = e => { child.kill('SIGKILL'); throw new Error(`${e.message}\n${log}`); };
// The first heartbeat marks the worker 'online' before its WebSocket is connected,
// so wait until the server actually accepts a command for it (a harmless `true`).
const worker = await waitFor(async () => {
const w = await workerByName(name);
return w && w.status === 'online' ? w : null;
}, { what: `worker ${name} to come online` }).catch(e => { child.kill('SIGKILL'); throw new Error(`${e.message}\n${log}`); });
}, { what: `worker ${name} to register` }).catch(fail);
const probe = await waitFor(async () => {
const r = await gandalf('POST', '/api/internal/command', { worker_id: worker.id, command: 'true' });
return r.status === 200 ? r.json.execution_id : null;
}, { what: `worker ${name} to connect its WebSocket` }).catch(fail);
await waitForExecution(probe).catch(fail);
return {
id: worker.id,
child,
@@ -88,7 +96,10 @@ async function startWorker(name, env = {}) {
await new Promise(r => child.once('exit', r));
}
// Remove it so other suites (and the UI tests' worker counts) don't see it.
await waitFor(async () => (await workerByName(name))?.status === 'offline', { timeout: 5_000, what: `${name} to show offline` });
// Never throws: cleanup must not hide the test's own failure. The offline
// status itself is asserted by its own test in reliability.int.js.
await waitFor(async () => (await workerByName(name))?.status === 'offline', { timeout: 5_000, what: `${name} offline` })
.catch(e => console.warn(`cleanup: ${e.message}`));
await sso('DELETE', `/api/workers/${worker.id}`);
},
};