fix(test): improve capture reliability and runner cleanup (#609)

* test: make capture fixtures readiness-aware and strengthen assertions

* fix(test): escalate child termination and report cleanup failures

* perf(test): use runner concurrency and lock shared build outputs
This commit is contained in:
morluto
2026-10-06 01:32:46 +08:00
committed by GitHub
parent bae87b4ded
commit d19686a2a5
14 changed files with 318 additions and 107 deletions
-1
View File
@@ -62,7 +62,6 @@ export const developmentTestPlan = (request, baseCommit) => {
needsBuild: request.paths.some((path) => !sourceTest(path)),
vitestArguments: [
"run",
"--maxWorkers=1",
...projects.flatMap((project) => ["--project", project]),
...(explicit
? request.paths
+20 -15
View File
@@ -8,12 +8,18 @@ import {
} from "./lib/development-tests.mjs";
let child;
let forceTimer;
let shutdownSignal;
const signalExitCodes = { SIGINT: 130, SIGTERM: 143 };
for (const signal of Object.keys(signalExitCodes))
process.on(signal, () => {
shutdownSignal ??= signal;
child?.kill(signal);
if (shutdownSignal !== undefined) return;
shutdownSignal = signal;
if (child !== undefined && child.exitCode === null) {
child.kill(signal);
forceTimer = setTimeout(() => child?.kill("SIGKILL"), 1_000);
forceTimer.unref?.();
}
});
try {
@@ -71,20 +77,19 @@ function run(executable, arguments_, capture = false) {
code: signalExitCodes[shutdownSignal],
output: "",
});
child = spawn(executable, arguments_, {
stdio: capture ? ["ignore", "pipe", "pipe"] : "inherit",
});
let output = "";
if (capture) {
child.stdout.on("data", (data) => (output += data.toString()));
child.stderr.on("data", (data) => (output += data.toString()));
}
return new Promise((resolveResult, reject) => {
let output = "";
child = spawn(executable, arguments_, {
stdio: capture ? ["ignore", "pipe", "pipe"] : "inherit",
});
if (capture) {
child.stdout.on("data", (data) => {
output += data.toString();
});
child.stderr.on("data", (data) => {
output += data.toString();
});
}
child.once("error", reject);
child.once("close", (code) => resolveResult({ code: code ?? 1, output }));
child.once("close", (code) => {
clearTimeout(forceTimer);
resolveResult({ code: code ?? 1, output });
});
});
}
+10 -2
View File
@@ -12,6 +12,7 @@ const signalExitCodes = { SIGINT: 130, SIGTERM: 143 };
let lockHeld = false;
let child;
let forceTimer;
let shutdownSignal;
process.on("SIGINT", () => handleSignal("SIGINT"));
@@ -96,14 +97,21 @@ function runCommand() {
stdio: "inherit",
});
child.once("error", reject);
child.once("close", (code) => resolveResult({ code }));
child.once("close", (code) => {
clearTimeout(forceTimer);
resolveResult({ code });
});
});
}
function handleSignal(signal) {
if (shutdownSignal !== undefined) return;
shutdownSignal = signal;
if (child !== undefined && child.exitCode === null) child.kill(signal);
if (child !== undefined && child.exitCode === null) {
child.kill(signal);
forceTimer = setTimeout(() => child?.kill("SIGKILL"), 1_000);
forceTimer.unref?.();
}
}
async function readOwner() {