fix(test): serialize local heavy checks (#60273)

This commit is contained in:
Vincent Koc 2026-04-03 21:07:56 +09:00 committed by GitHub
parent feca4aa49e
commit 4846ebce12
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 1 deletions

View File

@ -1,8 +1,24 @@
import { spawn } from "node:child_process";
import { acquireLocalHeavyCheckLockSync } from "./lib/local-heavy-check-runtime.mjs";
import { buildVitestArgs } from "./test-projects.test-support.mjs";
const command = process.platform === "win32" ? "pnpm.cmd" : "pnpm";
const vitestArgs = buildVitestArgs(process.argv.slice(2));
const releaseLock = acquireLocalHeavyCheckLockSync({
cwd: process.cwd(),
env: process.env,
lockName: "test",
toolName: "test",
});
let lockReleased = false;
const releaseLockOnce = () => {
if (lockReleased) {
return;
}
lockReleased = true;
releaseLock();
};
const child = spawn(command, vitestArgs, {
stdio: "inherit",
@ -10,6 +26,7 @@ const child = spawn(command, vitestArgs, {
});
child.on("exit", (code, signal) => {
releaseLockOnce();
if (signal) {
process.kill(process.pid, signal);
return;
@ -18,6 +35,7 @@ child.on("exit", (code, signal) => {
});
child.on("error", (error) => {
releaseLockOnce();
console.error(error);
process.exit(1);
});

View File

@ -36,7 +36,7 @@ process.env.VITEST = "true";
// Config validation walks plugin manifests; keep an aggressive cache in tests to avoid
// repeated filesystem discovery across suites/workers.
process.env.OPENCLAW_PLUGIN_MANIFEST_CACHE_MS ??= "60000";
// Vitest vm forks can load transitive lockfile helpers many times per worker.
// Vitest fork workers can load transitive lockfile helpers many times per worker.
// Raise listener budget to avoid noisy MaxListeners warnings and warning-stack overhead.
const TEST_PROCESS_MAX_LISTENERS = 128;
if (process.getMaxListeners() > 0 && process.getMaxListeners() < TEST_PROCESS_MAX_LISTENERS) {