From 0412eeeb38336845ff7aeff4cd53e4cf3185adec Mon Sep 17 00:00:00 2001 From: Jared Vititoe Date: Mon, 23 Nov 2026 15:54:53 -0500 Subject: [PATCH] Fix a race in the cancel_command test The shell creates a redirect target before writing to it, so the test could read an empty pid file, take pid 0, and decide the child was not running. This failed the push run of #80's merge, so that commit was not deployed. The command now writes the pid to a temporary file and renames it into place. Co-Authored-By: Claude Opus 5.5 --- tests/worker.test.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/worker.test.js b/tests/worker.test.js index 235139a..443f912 100644 --- a/tests/worker.test.js +++ b/tests/worker.test.js @@ -126,7 +126,9 @@ describe('cancel_command (#8)', () => { test('cancelling stops the command and everything it started', async () => { const w = makeWorker(); const pidFile = path.join(fs.mkdtempSync(path.join(os.tmpdir(), 'pulse-cancel-')), 'pid'); - const pending = w.executeCommand({ command: `sleep 30 & echo $! > ${pidFile}; wait`, execution_id: 'ex-c', command_id: 'cmd-c' }); + // Write then rename: the shell creates a redirect target before writing to it, + // so reading ${pidFile} directly could see an empty file (pid 0). + const pending = w.executeCommand({ command: `sleep 30 & echo $! > ${pidFile}.tmp && mv ${pidFile}.tmp ${pidFile}; wait`, execution_id: 'ex-c', command_id: 'cmd-c' }); for (let i = 0; i < 50 && !fs.existsSync(pidFile); i++) await new Promise(r => setTimeout(r, 50)); const childPid = Number(fs.readFileSync(pidFile, 'utf8')); expect(alive(childPid)).toBe(true);