From 05980207c6a455ed0a84c4891c04be62e281c12e Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Thu, 16 Jul 2026 16:47:30 -0700 Subject: [PATCH] test: deflake test-group-report SIGTERM descendant-cleanup test (#109347) The child published its pid with a non-atomic writeFileSync while the test polled file existence only, so a loaded runner could read an empty pid file (NaN -> isProcessAlive false). Publish the pid via rename and widen the spawn-chain poll deadlines; assertion strength is unchanged. --- test/scripts/test-group-report.test.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/test/scripts/test-group-report.test.ts b/test/scripts/test-group-report.test.ts index 315ef9f812c0..1cc8ba9ff7ed 100644 --- a/test/scripts/test-group-report.test.ts +++ b/test/scripts/test-group-report.test.ts @@ -1107,10 +1107,14 @@ describe("scripts/test-group-report child process guard", () => { let childPid: number | undefined; let runner: ReturnType | undefined; try { + // Publish the pid via rename so it appears atomically: waitForFile polls + // existence only, and a direct writeFileSync leaves an empty-file window + // that made the pid parse as NaN (isProcessAlive false) on loaded CI. const childScript = [ "const fs = require('node:fs');", "process.on('SIGTERM', () => {});", - `fs.writeFileSync(${JSON.stringify(childPidPath)}, String(process.pid));`, + `fs.writeFileSync(${JSON.stringify(`${childPidPath}.tmp`)}, String(process.pid));`, + `fs.renameSync(${JSON.stringify(`${childPidPath}.tmp`)}, ${JSON.stringify(childPidPath)});`, "setInterval(() => {}, 1000);", ].join("\n"); const parentScript = [ @@ -1133,8 +1137,10 @@ describe("scripts/test-group-report child process guard", () => { cwd: process.cwd(), stdio: ["ignore", "ignore", "pipe"], }); - await waitForFile(readyPath, 2_000); - await waitForFile(childPidPath, 2_000); + // Generous poll deadlines: spawning the nested runner/parent/child node + // chain can take multiple seconds on loaded CI runners. + await waitForFile(readyPath, 10_000); + await waitForFile(childPidPath, 10_000); childPid = Number.parseInt(fs.readFileSync(childPidPath, "utf8"), 10); expect(isProcessAlive(childPid)).toBe(true); @@ -1144,7 +1150,7 @@ describe("scripts/test-group-report child process guard", () => { code: null, signal: "SIGTERM", }); - await waitForDead(childPid, 2_000); + await waitForDead(childPid, 10_000); } finally { if (runner?.pid && isProcessAlive(runner.pid)) { runner.kill("SIGKILL");