diff --git a/extensions/qa-lab/src/test-file-scenario-command-lifecycle.test.ts b/extensions/qa-lab/src/test-file-scenario-command-lifecycle.test.ts index 3c5cd1507396..d460f6ce4676 100644 --- a/extensions/qa-lab/src/test-file-scenario-command-lifecycle.test.ts +++ b/extensions/qa-lab/src/test-file-scenario-command-lifecycle.test.ts @@ -72,7 +72,6 @@ describe.skipIf(process.platform === "win32")("qa scenario command real POSIX li it("settles within a bound after the leader writes its final result with inherited stdio open", async () => { const root = await mkdtemp(path.join(os.tmpdir(), "qa-command-settlement-")); const descendantPidPath = path.join(root, "descendant.pid"); - let descendantPid: number | undefined; spawnMock.mockImplementation((...args: Parameters>) => { if (!actualSpawn.value) { throw new Error("real spawn unavailable"); @@ -102,7 +101,7 @@ describe.skipIf(process.platform === "win32")("qa scenario command real POSIX li env: process.env, timeoutMs: 5_000, }); - descendantPid = await waitForPidFile(descendantPidPath); + await waitForPidFile(descendantPidPath); const startedAt = Date.now(); const deadline = new AbortController(); const result = await Promise.race([ @@ -113,20 +112,15 @@ describe.skipIf(process.platform === "win32")("qa scenario command real POSIX li ]).finally(() => deadline.abort()); expect(Date.now() - startedAt).toBeLessThan(1_500); + // The exact result proves cleanup succeeded. A later numeric PID probe can + // race PID reuse and inspect an unrelated process. expect(result).toEqual({ exitCode: 7, signal: null, stdout: "Docker scheduling finished\ndelayed descendant output\n", stderr: "", }); - if (descendantPid === undefined) { - throw new Error("scenario command descendant did not expose its pid"); - } - await waitForDead(descendantPid); } finally { - if (descendantPid && isProcessAlive(descendantPid)) { - process.kill(descendantPid, "SIGKILL"); - } await rm(root, { force: true, recursive: true }); } });