From 2d4de656d2ab40072ee768b7540a79fd0d7f3f2c Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sat, 17 Jan 2026 19:20:40 +0000 Subject: [PATCH] test: avoid global SIGTERM emit in child-process-bridge --- src/process/child-process-bridge.test.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/process/child-process-bridge.test.ts b/src/process/child-process-bridge.test.ts index 128dae6de..d6c886d4a 100644 --- a/src/process/child-process-bridge.test.ts +++ b/src/process/child-process-bridge.test.ts @@ -79,6 +79,7 @@ describe("attachChildProcessBridge", () => { it("forwards SIGTERM to the wrapped child", async () => { const childPath = path.resolve(process.cwd(), "test/fixtures/child-process-bridge/child.js"); + const beforeSigterm = new Set(process.listeners("SIGTERM")); const child = spawn(process.execPath, [childPath], { stdio: ["ignore", "pipe", "inherit"], env: process.env, @@ -86,6 +87,8 @@ describe("attachChildProcessBridge", () => { const { detach } = attachChildProcessBridge(child); detachments.push(detach); children.push(child); + const afterSigterm = process.listeners("SIGTERM"); + const addedSigterm = afterSigterm.find((listener) => !beforeSigterm.has(listener)); if (!child.stdout) throw new Error("expected stdout"); const portLine = await waitForLine(child.stdout); @@ -95,7 +98,8 @@ describe("attachChildProcessBridge", () => { expect(await canConnect(port)).toBe(true); // Simulate systemd sending SIGTERM to the parent process. - process.emit("SIGTERM"); + if (!addedSigterm) throw new Error("expected SIGTERM listener"); + addedSigterm(); await new Promise((resolve, reject) => { const timeout = setTimeout(() => reject(new Error("timeout waiting for child exit")), 10_000);