From fa8ba1bd3b549845c1936b8c5072e210b0db1ebd Mon Sep 17 00:00:00 2001 From: "paseo-bot[bot]" <266920839+paseo-bot[bot]@users.noreply.github.com> Date: Mon, 16 Nov 2026 06:46:25 +0000 Subject: [PATCH] test(terminal): wait for the live worker's socket before reaping (#9835) The reaper signals a worker only after its socket accepts. The two "cannot be opened for a moment" tests spawned a listening worker and reaped without waiting for the listen, so on a loaded runner the reaper found no socket, left the worker alive, and the test failed after waitUntilGone's 5s deadline. Spawn the worker through a helper that resolves once the socket is listening, as the other socket tests in this file already do. Co-authored-by: paseo-bot[bot] <266920839+paseo-bot[bot]@users.noreply.github.com> --- .../terminal/terminal-worker-reaper.test.ts | 28 ++++++++----------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/packages/server/src/terminal/terminal-worker-reaper.test.ts b/packages/server/src/terminal/terminal-worker-reaper.test.ts index ef8d4fe487..753db72e0a 100644 --- a/packages/server/src/terminal/terminal-worker-reaper.test.ts +++ b/packages/server/src/terminal/terminal-worker-reaper.test.ts @@ -577,20 +577,27 @@ describe.skipIf(isPlatform("win32"))("terminal worker reaper", () => { // chmod cannot make a file unreadable to root. describe.skipIf(process.getuid?.() === 0)("a record that cannot be opened for a moment", () => { - it("still ends a live worker it names, then retires the record", async () => { - const home = makeHome(); + // The reaper signals a worker only once its socket accepts, so wait for the listen. + async function spawnListeningWorker(socketPath: string): Promise { const worker = spawn( process.execPath, [ "-e", - `require("node:net").createServer(() => {}).listen(${JSON.stringify(path.join(home, "live-record-under-test.sock"))});setInterval(() => {}, 1e9)`, + `require("node:net").createServer(() => {}).listen(${JSON.stringify(socketPath)}, () => process.stdout.write("listening\\n"));setInterval(() => {}, 1e9)`, "--", "--paseo-terminal-worker", "record-under-test", ], - { detached: true, stdio: "ignore" }, + { detached: true, stdio: ["ignore", "pipe", "ignore"] }, ); children.push(worker); + await new Promise((resolve) => worker.stdout!.once("data", resolve)); + return worker; + } + + it("still ends a live worker it names, then retires the record", async () => { + const home = makeHome(); + const worker = await spawnListeningWorker(path.join(home, "live-record-under-test.sock")); const recordPath = writeRecord(home, { pid: worker.pid!, socketPath: path.join(home, "live-record-under-test.sock"), @@ -632,18 +639,7 @@ describe.skipIf(isPlatform("win32"))("terminal worker reaper", () => { it("still reports a record that stays unreadable, and signals nothing it names", async () => { const home = makeHome(); - const worker = spawn( - process.execPath, - [ - "-e", - `require("node:net").createServer(() => {}).listen(${JSON.stringify(path.join(home, "live-record-under-test.sock"))});setInterval(() => {}, 1e9)`, - "--", - "--paseo-terminal-worker", - "record-under-test", - ], - { detached: true, stdio: "ignore" }, - ); - children.push(worker); + const worker = await spawnListeningWorker(path.join(home, "live-record-under-test.sock")); const recordPath = writeRecord(home, { pid: worker.pid!, socketPath: path.join(home, "live-record-under-test.sock"),