Tests: serialize low-memory test runner lanes

This commit is contained in:
Vincent Koc
2026-03-06 17:45:35 -05:00
parent 6e962d8b9e
commit a190220967

View File

@@ -111,8 +111,17 @@ const useVmForks =
const disableIsolation = process.env.OPENCLAW_TEST_NO_ISOLATE === "1"; const disableIsolation = process.env.OPENCLAW_TEST_NO_ISOLATE === "1";
const includeGatewaySuite = process.env.OPENCLAW_TEST_INCLUDE_GATEWAY === "1"; const includeGatewaySuite = process.env.OPENCLAW_TEST_INCLUDE_GATEWAY === "1";
const includeExtensionsSuite = process.env.OPENCLAW_TEST_INCLUDE_EXTENSIONS === "1"; const includeExtensionsSuite = process.env.OPENCLAW_TEST_INCLUDE_EXTENSIONS === "1";
const rawTestProfile = process.env.OPENCLAW_TEST_PROFILE?.trim().toLowerCase();
const testProfile =
rawTestProfile === "low" ||
rawTestProfile === "max" ||
rawTestProfile === "normal" ||
rawTestProfile === "serial"
? rawTestProfile
: "normal";
const shouldSplitUnitRuns = testProfile !== "low" && testProfile !== "serial";
const runs = [ const runs = [
...(useVmForks ...(shouldSplitUnitRuns
? [ ? [
{ {
name: "unit-fast", name: "unit-fast",
@@ -121,7 +130,7 @@ const runs = [
"run", "run",
"--config", "--config",
"vitest.unit.config.ts", "vitest.unit.config.ts",
"--pool=vmForks", `--pool=${useVmForks ? "vmForks" : "forks"}`,
...(disableIsolation ? ["--isolate=false"] : []), ...(disableIsolation ? ["--isolate=false"] : []),
...unitIsolatedFiles.flatMap((file) => ["--exclude", file]), ...unitIsolatedFiles.flatMap((file) => ["--exclude", file]),
], ],
@@ -141,7 +150,14 @@ const runs = [
: [ : [
{ {
name: "unit", name: "unit",
args: ["vitest", "run", "--config", "vitest.unit.config.ts"], args: [
"vitest",
"run",
"--config",
"vitest.unit.config.ts",
`--pool=${useVmForks ? "vmForks" : "forks"}`,
...(disableIsolation ? ["--isolate=false"] : []),
],
}, },
]), ]),
...(includeExtensionsSuite ...(includeExtensionsSuite
@@ -207,14 +223,7 @@ const silentArgs =
const rawPassthroughArgs = process.argv.slice(2); const rawPassthroughArgs = process.argv.slice(2);
const passthroughArgs = const passthroughArgs =
rawPassthroughArgs[0] === "--" ? rawPassthroughArgs.slice(1) : rawPassthroughArgs; rawPassthroughArgs[0] === "--" ? rawPassthroughArgs.slice(1) : rawPassthroughArgs;
const rawTestProfile = process.env.OPENCLAW_TEST_PROFILE?.trim().toLowerCase(); const topLevelParallelEnabled = testProfile !== "low" && testProfile !== "serial";
const testProfile =
rawTestProfile === "low" ||
rawTestProfile === "max" ||
rawTestProfile === "normal" ||
rawTestProfile === "serial"
? rawTestProfile
: "normal";
const overrideWorkers = Number.parseInt(process.env.OPENCLAW_TEST_WORKERS ?? "", 10); const overrideWorkers = Number.parseInt(process.env.OPENCLAW_TEST_WORKERS ?? "", 10);
const resolvedOverride = const resolvedOverride =
Number.isFinite(overrideWorkers) && overrideWorkers > 0 ? overrideWorkers : null; Number.isFinite(overrideWorkers) && overrideWorkers > 0 ? overrideWorkers : null;
@@ -399,6 +408,23 @@ const run = async (entry) => {
return 0; return 0;
}; };
const runEntries = async (entries) => {
if (topLevelParallelEnabled) {
const codes = await Promise.all(entries.map(run));
return codes.find((code) => code !== 0);
}
for (const entry of entries) {
// eslint-disable-next-line no-await-in-loop
const code = await run(entry);
if (code !== 0) {
return code;
}
}
return undefined;
};
const shutdown = (signal) => { const shutdown = (signal) => {
for (const child of children) { for (const child of children) {
child.kill(signal); child.kill(signal);
@@ -451,8 +477,7 @@ if (passthroughArgs.length > 0) {
process.exit(Number(code) || 0); process.exit(Number(code) || 0);
} }
const parallelCodes = await Promise.all(parallelRuns.map(run)); const failedParallel = await runEntries(parallelRuns);
const failedParallel = parallelCodes.find((code) => code !== 0);
if (failedParallel !== undefined) { if (failedParallel !== undefined) {
process.exit(failedParallel); process.exit(failedParallel);
} }