mirror of
https://github.com/morluto/rea.git
synced 2026-11-18 20:53:00 +00:00
Where PID 1 does not reap orphans promptly, a killed descendant stays a zombie for a while. Signal 0 still reaches a zombie, and a raw process table still lists it, so four boundary tests decided a stopped process was alive although cleanup had worked. The stop assertions in artifactVerifierCleanupOwner and desktopBuildOwnedCommand now use processHasStopped. The run-token sweep in ownedCommand reads the product's liveProcesses view, which drops zombie rows. The testing guide says to assert a stop this way and not with signal 0. Ported onto current main from morluto/rea#11837. The helper and the first eight cases landed in morluto/rea#12034, so this keeps the four that remained. Co-authored-by: Dayan Kijege <dayanusa7@gmail.com>
102 lines
4.5 KiB
TypeScript
102 lines
4.5 KiB
TypeScript
import { mkdir, readFile, stat } from "node:fs/promises";
|
|
import { join } from "node:path";
|
|
import { expect, it } from "vitest";
|
|
|
|
import { ArtifactResourceScope } from "../../../src/resources/ArtifactResourceScope.js";
|
|
import { runDesktopBuildOwnedCommand } from "../../../src/desktop/DesktopBuildOwnedCommand.js";
|
|
import { prepareProcessOwnershipInspection } from "../../../src/process/ProcessOwnershipObservation.js";
|
|
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
|
import { processHasStopped } from "../../support/process/observePosixProcess.js";
|
|
import { waitFor } from "../../support/testWait.js";
|
|
|
|
it.skipIf(process.platform === "win32")(
|
|
"stops the packing process family before removing its partial archive on timeout",
|
|
async () => {
|
|
await prepareProcessOwnershipInspection();
|
|
const directory = await createTestTempDirectory("rea-owned-pack-");
|
|
const partial = join(directory, "partial.tar.xz");
|
|
const workspace = join(directory, "work");
|
|
await mkdir(workspace);
|
|
const pidFile = join(directory, "child.pid");
|
|
const child = `require('node:fs').writeFileSync(process.argv[1], String(process.pid)); require('node:fs').writeFileSync(require('node:path').join(require('node:os').tmpdir(), 'child-work'), 'temporary'); setInterval(() => {}, 1000);`;
|
|
const parent = `const {spawn} = require('node:child_process'); require('node:fs').writeFileSync(process.argv[1], 'partial'); spawn(process.execPath, ['-e', process.argv[3], process.argv[2]], {stdio:'inherit'}); setInterval(() => {}, 1000);`;
|
|
const resources = new ArtifactResourceScope();
|
|
try {
|
|
await expect(
|
|
runDesktopBuildOwnedCommand({
|
|
command: process.execPath,
|
|
arguments: ["-e", parent, partial, pidFile, child],
|
|
environment: {
|
|
...process.env,
|
|
TMPDIR: workspace,
|
|
TMP: workspace,
|
|
TEMP: workspace,
|
|
},
|
|
timeoutMs: 2000,
|
|
maxOutputBytes: 4096,
|
|
resources,
|
|
partialPath: partial,
|
|
workspace,
|
|
}),
|
|
).rejects.toMatchObject({
|
|
_tag: "AnalysisOutputError",
|
|
operation: "setup",
|
|
diagnostics: { command_failure: "timeout" },
|
|
});
|
|
const pid = Number(await readFile(pidFile, "utf8"));
|
|
expect(Number.isInteger(pid)).toBe(true);
|
|
expect(await processHasStopped(pid)).toBe(true);
|
|
await expect(stat(partial)).rejects.toMatchObject({ code: "ENOENT" });
|
|
await expect(stat(workspace)).rejects.toMatchObject({ code: "ENOENT" });
|
|
expect(resources.hasPending).toBe(false);
|
|
} finally {
|
|
await resources.close();
|
|
}
|
|
},
|
|
);
|
|
|
|
it.skipIf(process.platform === "win32")(
|
|
"cancels a running setup process family before removing its partial output",
|
|
async () => {
|
|
await prepareProcessOwnershipInspection();
|
|
const directory = await createTestTempDirectory("rea-owned-pack-cancel-");
|
|
const partial = join(directory, "partial.tar.xz");
|
|
const pidFile = join(directory, "child.pid");
|
|
const child = `require('node:fs').writeFileSync(process.argv[1], String(process.pid)); setInterval(() => {}, 1000);`;
|
|
const parent = `const {spawn} = require('node:child_process'); require('node:fs').writeFileSync(process.argv[1], 'partial'); spawn(process.execPath, ['-e', process.argv[3], process.argv[2]], {stdio:'inherit'}); setInterval(() => {}, 1000);`;
|
|
const resources = new ArtifactResourceScope();
|
|
const controller = new AbortController();
|
|
const reason = new Error("caller stopped setup");
|
|
const running = runDesktopBuildOwnedCommand({
|
|
command: process.execPath,
|
|
arguments: ["-e", parent, partial, pidFile, child],
|
|
environment: process.env,
|
|
timeoutMs: 10_000,
|
|
maxOutputBytes: 4096,
|
|
resources,
|
|
partialPath: partial,
|
|
signal: controller.signal,
|
|
});
|
|
void running.catch(() => undefined);
|
|
try {
|
|
await waitFor(async () => {
|
|
expect(Number(await readFile(pidFile, "utf8"))).toBeGreaterThan(0);
|
|
});
|
|
const pid = Number(await readFile(pidFile, "utf8"));
|
|
controller.abort(reason);
|
|
await expect(running).rejects.toMatchObject({
|
|
_tag: "AnalysisCancelledError",
|
|
operation: "setup",
|
|
cause: reason,
|
|
diagnostics: { command_failure: "cancelled" },
|
|
});
|
|
expect(await processHasStopped(pid)).toBe(true);
|
|
await expect(stat(partial)).rejects.toMatchObject({ code: "ENOENT" });
|
|
} finally {
|
|
controller.abort(reason);
|
|
await running.catch(() => undefined);
|
|
await resources.close();
|
|
}
|
|
},
|
|
);
|