Worker unit tests, coverage floors, and an SBOM per main build #52
@@ -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}`);
|
||||
},
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user