Integration tests for the Gandalf contract, auth and reliability; fix worker offline status
CI / Lint (eslint) (push) Successful in 46s
CI / Security (npm audit) (push) Successful in 26s
CI / Integration (api) (push) Successful in 1m31s
CI / Test (jest) (pull_request) Successful in 50s
CI / UI (playwright) (push) Successful in 2m31s
CI / Integration (api) (pull_request) Successful in 1m58s
CI / Test (jest) (push) Successful in 13s
CI / Deploy (push) Skipped
CI / Notify (push) Skipped
CI / UI (playwright) (pull_request) Successful in 2m16s
CI / Lint (eslint) (pull_request) Successful in 15s
CI / Security (npm audit) (pull_request) Successful in 15s
CI / Deploy (pull_request) Skipped
CI / Notify (pull_request) Skipped
CI / Lint (eslint) (push) Successful in 46s
CI / Security (npm audit) (push) Successful in 26s
CI / Integration (api) (push) Successful in 1m31s
CI / Test (jest) (pull_request) Successful in 50s
CI / UI (playwright) (push) Successful in 2m31s
CI / Integration (api) (pull_request) Successful in 1m58s
CI / Test (jest) (push) Successful in 13s
CI / Deploy (push) Skipped
CI / Notify (push) Skipped
CI / UI (playwright) (pull_request) Successful in 2m16s
CI / Lint (eslint) (pull_request) Successful in 15s
CI / Security (npm audit) (pull_request) Successful in 15s
CI / Deploy (pull_request) Skipped
CI / Notify (pull_request) Skipped
New CI job `Integration (api)` (#45 phase 3) runs the real server and three workers on Node 20 against MariaDB and tests them as a black box over HTTP and WebSocket (20 tests, about 12 s): - Gandalf contract: submit and poll, stdout from command_result, failures with exit code and stderr, 401 for wrong or missing key, 400 for missing fields or an unknown worker, 404 for an unknown execution - Auth: SSO identity, 401/403, heartbeat key, /healthz exposes only status; WebSocket upgrade refused without credentials, with a wrong key or a wrong group; live events reach a signed-in browser; a browser socket cannot forge a command result - Reliability: a worker killed mid-command fails the execution at once; a worker at capacity answers with a failure; an aborted execution stays failed when the late result arrives; a disconnected worker shows offline The last test found a bug from #42: the close handler deleted the worker's runtime-id entry before checking whether the socket was still live under its database id, and the two ids are normally the same key. So a disconnected worker was never marked offline and showed 'online' until the stale heartbeat sweep. Gandalf was unaffected (it checks live sockets). MariaDB setup for CI moves to scripts/ci/mariadb.sh, shared by both jobs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
1d5b8cdd53
commit
def926d41e
11 files changed
+391
-21
No files matched your search
@@ -0,0 +1,62 @@
|
||||
'use strict';
|
||||
|
||||
// Executions always reach a final state (#7), and a final state is final.
|
||||
const { sso, gandalf, startWorker, waitForExecution, commandResult, sleep, waitFor, workerByName } = require('./helpers');
|
||||
|
||||
const unique = () => `int-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 6)}`;
|
||||
|
||||
test('a worker that dies mid-command fails the execution at once, not hours later', async () => {
|
||||
const w = await startWorker(unique());
|
||||
try {
|
||||
const submit = await gandalf('POST', '/api/internal/command', { worker_id: w.id, command: 'sleep 30' });
|
||||
expect(submit.status).toBe(200);
|
||||
await sleep(500);
|
||||
w.child.kill('SIGKILL');
|
||||
|
||||
const ex = await waitForExecution(submit.json.execution_id, { timeout: 15_000 });
|
||||
expect(ex.status).toBe('failed');
|
||||
expect(commandResult(ex).error).toMatch(/disconnected/i);
|
||||
} finally { await w.stop(); }
|
||||
});
|
||||
|
||||
test('a worker that disconnects shows offline at once', async () => {
|
||||
const name = unique();
|
||||
const w = await startWorker(name);
|
||||
try {
|
||||
w.child.kill('SIGKILL');
|
||||
// Not after the stale-heartbeat sweep: the socket close marks it offline.
|
||||
await waitFor(async () => (await workerByName(name))?.status === 'offline', { timeout: 3_000, what: 'offline status' });
|
||||
} finally { await w.stop(); }
|
||||
});
|
||||
|
||||
test('a worker at capacity answers with a failure instead of staying silent', async () => {
|
||||
const w = await startWorker(unique(), { MAX_CONCURRENT_TASKS: '1' });
|
||||
try {
|
||||
const first = await gandalf('POST', '/api/internal/command', { worker_id: w.id, command: 'sleep 3; echo first' });
|
||||
await sleep(300);
|
||||
const second = await gandalf('POST', '/api/internal/command', { worker_id: w.id, command: 'echo second' });
|
||||
|
||||
const ex2 = await waitForExecution(second.json.execution_id, { timeout: 10_000 });
|
||||
expect(ex2.status).toBe('failed');
|
||||
expect(commandResult(ex2).error).toMatch(/capacity/i);
|
||||
|
||||
const ex1 = await waitForExecution(first.json.execution_id);
|
||||
expect(ex1.status).toBe('completed');
|
||||
} finally { await w.stop(); }
|
||||
});
|
||||
|
||||
test('an aborted execution stays failed when the worker reports back later', async () => {
|
||||
const w = await startWorker(unique());
|
||||
try {
|
||||
const submit = await gandalf('POST', '/api/internal/command', { worker_id: w.id, command: 'sleep 2; echo late' });
|
||||
const id = submit.json.execution_id;
|
||||
await sleep(300);
|
||||
expect((await sso('POST', `/api/executions/${id}/abort`)).status).toBe(200);
|
||||
|
||||
await sleep(3500); // the command finishes and the worker sends its result
|
||||
const ex = await waitForExecution(id);
|
||||
expect(ex.status).toBe('failed');
|
||||
expect((ex.logs || []).some(l => l.action === 'execution_aborted')).toBe(true);
|
||||
expect((ex.logs || []).some(l => l.action === 'command_result' && l.success)).toBe(false);
|
||||
} finally { await w.stop(); }
|
||||
});
|
||||
Reference in new issue
Block a user