From 74ddacf53b47004c102b21566df9340217582d5c Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sat, 24 Oct 2026 05:19:08 +0200 Subject: [PATCH] Tests: a worker that ignores SIGTERM is dead within a second of a loss; its output while the daemon stops is not copied Co-Authored-By: Claude Opus 5.5 --- scripts/fixtures/stub-worker.mjs | 8 ++++++-- scripts/test-vili-daemon.mjs | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/scripts/fixtures/stub-worker.mjs b/scripts/fixtures/stub-worker.mjs index 0b5e6ae..3cf1831 100644 --- a/scripts/fixtures/stub-worker.mjs +++ b/scripts/fixtures/stub-worker.mjs @@ -1,7 +1,7 @@ // Stands in for kimodo-resident-worker.py in the daemon's tests. It binds port 0, prints the ready line the // daemon waits for, and answers /health and /generate with what the daemon gave it. The --model value picks a // misbehaviour: crash-before-ready, hang-before-ready, sick, slow-health, stubborn, fail-generate, -// refuse-generate, drop-generate, slow-generate, writer (appends to .writes every 50 ms and never answers), slow-to-stop (no answer; exits 1.5 s after SIGTERM), chatty (prints a line the moment it is healthy), encoder (a grandchild, then no answer), graceful (exits 0.5 s after SIGTERM), die-after-ready. Any other value is just the model the worker serves. +// refuse-generate, drop-generate, slow-generate, writer (appends to .writes every 50 ms, never answers, ignores SIGTERM), slow-to-stop (no answer; prints a line and exits 1.5 s after SIGTERM), chatty (prints a line the moment it is healthy), encoder (a grandchild, then no answer), graceful (exits 0.5 s after SIGTERM), die-after-ready. Any other value is just the model the worker serves. import http from "node:http"; import os from "node:os"; import path from "node:path"; @@ -33,7 +33,11 @@ if (model === "stubborn") { spawn(process.execPath, ["-e", `process.on('SIGTERM', () => {}); require('fs').appendFileSync(${JSON.stringify(spawnLog)}, 'grandchild ' + process.pid + '\\n'); setInterval(() => {}, 1000)`], { stdio: "ignore" }); } -if (model === "slow-to-stop") process.on("SIGTERM", () => setTimeout(() => process.exit(0), 1500)); +if (model === "slow-to-stop") process.on("SIGTERM", () => { + console.log("stopping-line"); // output while it stops + setTimeout(() => process.exit(0), 1500); +}); +if (model === "writer") process.on("SIGTERM", () => {}); // a worker that carries on writing through SIGTERM if (model === "graceful") { process.on("SIGTERM", () => { diff --git a/scripts/test-vili-daemon.mjs b/scripts/test-vili-daemon.mjs index 362c4b9..c6c14f6 100644 --- a/scripts/test-vili-daemon.mjs +++ b/scripts/test-vili-daemon.mjs @@ -1173,6 +1173,7 @@ for (const kind of ["fake Idunn entry", "hand-run"]) { assert.deepEqual(readdirSync(path.join(daemon.stateRoot, "artifacts")), artifacts, "no artifact is created after the signal"); assert.deepEqual(readdirSync(path.join(daemon.stateRoot, "jobs")), [], "no job is recorded after the signal"); assert.equal(statSync(store).mtimeMs, storeBefore); + assert.ok(!readFileSync(path.join(daemon.stateRoot, "logs", "worker.log"), "utf8").includes("stopping-line"), "the worker's output while it stops is not copied"); } finally { await daemon.stop(); }