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");