test: stabilize full-suite flakes

This commit is contained in:
Peter Steinberger
2026-04-23 18:47:25 +01:00
parent d0303e2a97
commit 310b1eea4a
7 changed files with 72 additions and 15 deletions

View File

@@ -145,9 +145,9 @@ export async function runChangedCheck(result, options = {}) {
}
} else if (plan.runChangedTestsBroad) {
const testArgs = options.explicitPaths
? ["scripts/test-projects.mjs"]
: ["scripts/test-projects.mjs", "--changed", options.base ?? "origin/main"];
const status = await runNode(
? ["test"]
: ["test", "--changed", options.base ?? "origin/main"];
const status = await runPnpm(
{
name: options.explicitPaths ? "tests all" : "tests changed broad",
args: testArgs,
@@ -159,10 +159,10 @@ export async function runChangedCheck(result, options = {}) {
return status;
}
} else if (plan.testTargets.length > 0) {
const status = await runNode(
const status = await runPnpm(
{
name: "tests changed",
args: ["scripts/test-projects.mjs", ...plan.testTargets],
args: ["test", ...plan.testTargets],
},
timings,
);
@@ -209,10 +209,6 @@ async function runPnpm(command, timings) {
return await runCommand({ ...command, bin: "pnpm" }, timings);
}
async function runNode(command, timings) {
return await runCommand({ ...command, bin: process.execPath }, timings);
}
async function runCommand(command, timings) {
const startedAt = performance.now();
console.error(`\n[check:changed] ${command.name}`);

View File

@@ -180,7 +180,13 @@ export function forwardVitestOutput(stream, target, shouldSuppressLine = () => f
});
}
export function spawnWatchedVitestProcess({ pnpmArgs, spawnParams, env, label }) {
export function spawnWatchedVitestProcess({
pnpmArgs,
spawnParams,
env,
label,
onNoOutputTimeout,
}) {
const child = spawnVitestProcess({
pnpmArgs,
spawnParams,
@@ -194,6 +200,7 @@ export function spawnWatchedVitestProcess({ pnpmArgs, spawnParams, env, label })
console.error(message);
},
onTimeout: () => {
onNoOutputTimeout?.();
forwardSignalToVitestProcessGroup({
child,
signal: "SIGTERM",

View File

@@ -189,11 +189,15 @@ function runVitestSpec(spec) {
if (spec.includeFilePath && spec.includePatterns) {
writeVitestIncludeFile(spec.includeFilePath, spec.includePatterns);
}
let noOutputTimedOut = false;
return new Promise((resolve, reject) => {
const { child, teardown } = spawnWatchedVitestProcess({
pnpmArgs: spec.pnpmArgs,
env: spec.env,
label: spec.config,
onNoOutputTimeout: () => {
noOutputTimedOut = true;
},
spawnParams: {
cwd: process.cwd(),
...resolveVitestSpawnParams(spec.env),
@@ -203,7 +207,7 @@ function runVitestSpec(spec) {
child.on("exit", (code, signal) => {
teardown();
cleanupVitestRunSpec(spec);
resolve({ code: code ?? 1, signal });
resolve({ code: code ?? (signal ? 143 : 1), noOutputTimedOut, signal });
});
child.on("error", (error) => {
@@ -231,8 +235,21 @@ function applyDefaultParallelVitestWorkerBudget(specs, env) {
async function runLoggedVitestSpec(spec) {
console.error(`[test] starting ${spec.config}`);
const startedAt = performance.now();
const result = await runVitestSpec(spec);
let result = await runVitestSpec(spec);
if (result.noOutputTimedOut && !spec.watchMode) {
console.error(`[test] retrying ${spec.config} after no-output timeout`);
result = await runVitestSpec(spec);
}
const durationMs = performance.now() - startedAt;
if (result.noOutputTimedOut && result.signal) {
console.error(`[test] ${spec.config} exceeded no-output timeout`);
return {
...result,
code: result.code || 143,
signal: null,
timing: null,
};
}
if (result.signal) {
console.error(`[test] ${spec.config} exited by signal ${result.signal}`);
releaseLockOnce();