diff --git a/scripts/lib/clean-linux-hopper-runtime.mjs b/scripts/lib/clean-linux-hopper-runtime.mjs index 4d6bc8163..9f967ec05 100644 --- a/scripts/lib/clean-linux-hopper-runtime.mjs +++ b/scripts/lib/clean-linux-hopper-runtime.mjs @@ -17,8 +17,9 @@ export const assertCleanLinuxHopperRuntime = async ( : [process.env.HOPPER_LAUNCHER_PATH]), ], procRoot = "/proc", + listProcesses = () => execFileAsync("ps", ["-ax", "-o", "command="]), ) => { - const { stdout } = await execFileAsync("ps", ["-ax", "-o", "command="]); + const { stdout } = await listProcesses(); if (/\/opt\/hopper\/bin\/Hopper|\bXvfb\b|hopper-demo-x11\.py/u.test(stdout)) throw new Error("Clean Linux runner retained a Hopper demo process"); const launchers = []; diff --git a/tests/process-global/cleanLinuxHopperRuntime.test.ts b/tests/process-global/cleanLinuxHopperRuntime.test.ts index 8b7be17da..31df1f1ca 100644 --- a/tests/process-global/cleanLinuxHopperRuntime.test.ts +++ b/tests/process-global/cleanLinuxHopperRuntime.test.ts @@ -34,6 +34,10 @@ it const procRoot = join(directory, "proc"); await mkdir(procRoot); const alternateMode = mode === "alternate launcher"; + let orphanPid: number | undefined; + const isolatedProcessList = async () => ({ + stdout: orphanPid === undefined ? "" : "Xvfb", + }); if (alternateMode) { await copyFile("/usr/bin/sleep", launcher); await chmod(launcher, 0o700); @@ -44,6 +48,7 @@ it await assertCleanLinuxHopperRuntime( alternateMode ? [launcher] : [], procRoot, + isolatedProcessList, ); const command = alternateMode ? alternate : process.execPath; const arguments_ = alternateMode ? ["30"] : ["-e", childCode]; @@ -66,7 +71,6 @@ it const parentPid = parent.child.pid; if (parentPid === undefined) throw new Error("Fixture parent did not spawn"); - let orphanPid: number | undefined; try { const { stdout } = await parent; const { pid } = JSON.parse(stdout) as { pid: number }; @@ -112,6 +116,7 @@ it assertCleanLinuxHopperRuntime( alternateMode ? [launcher] : [], procRoot, + isolatedProcessList, ), ).rejects.toThrow("Clean Linux runner retained a Hopper demo process"); // Observation must not terminate the fixture, even though it resembles Xvfb.