From c5aa06607804c878bc7c423a5e80145c51d17ba5 Mon Sep 17 00:00:00 2001 From: Mradul Singh Date: Fri, 13 Nov 2026 15:59:25 +0530 Subject: [PATCH 1/3] fix(run): wait for the runner's count before the next test under --max-failures --- .changeset/max-failures-worker-wait.md | 6 +++ packages/e2e/src/run/execute.ts | 7 +++ packages/e2e/src/run/scheduler.ts | 20 ++++--- packages/e2e/src/run/worker/protocol.ts | 36 ++++++++----- packages/e2e/src/run/worker/session.ts | 52 +++++++++++++------ .../integration/parallel-workers.test.ts | 43 +++++++++++++++ 6 files changed, 127 insertions(+), 37 deletions(-) create mode 100644 .changeset/max-failures-worker-wait.md diff --git a/.changeset/max-failures-worker-wait.md b/.changeset/max-failures-worker-wait.md new file mode 100644 index 000000000..0033d2c0b --- /dev/null +++ b/.changeset/max-failures-worker-wait.md @@ -0,0 +1,6 @@ +--- +"e2e": patch +--- + +With several workers, `--max-failures` no longer lets the worker whose failure reaches the limit start its next test. That test was cancelled a moment later and reported `interrupted`; it is now skipped with cause `failure-limit`, as the docs say. +The runner alone counts failures toward the limit, and a worker waits for its answer to each failure before it starts another test. diff --git a/packages/e2e/src/run/execute.ts b/packages/e2e/src/run/execute.ts index 06f525b15..1e0842b5b 100644 --- a/packages/e2e/src/run/execute.ts +++ b/packages/e2e/src/run/execute.ts @@ -108,6 +108,12 @@ export interface TargetExecutorOptions extends EngineSessionsOptions { readonly holdStep?: ((step: HeldStep, signal: AbortSignal) => Promise) | undefined; /** Whether each hold reads the screen it starts on into `HeldStep.screen`. */ readonly heldScreens?: boolean | undefined; + /** + * Awaited before each pair of a file unit, ahead of the interrupt check: + * a worker holds its next test here until the runner has answered the + * failures it reported (see `RunUnitMessage.failureLimit`). + */ + readonly beforePair?: (() => Promise) | undefined; readonly events?: ExecutionEvents; /** The virtual file of tests registered in memory, and the agents they run as; see `InMemoryAttempts`. */ readonly inMemory?: InMemoryAttempts | undefined; @@ -271,6 +277,7 @@ export class TargetExecutor extends EngineSessions implements SerialHost { const serialUnitKey = pair.test.serialId === undefined ? undefined : pairKey(pair.test.serialId, pair.agent, pair.repeat); if (serialUnitKey !== undefined && executedSerialUnits.has(serialUnitKey)) continue; + await this.options.beforePair?.(); if (this.interruptSignal.aborted) { this.emit(unstartedResult(pair, interruptedSkip(this.interruptSignal))); continue; diff --git a/packages/e2e/src/run/scheduler.ts b/packages/e2e/src/run/scheduler.ts index 89ea63063..1e4ec9a5f 100644 --- a/packages/e2e/src/run/scheduler.ts +++ b/packages/e2e/src/run/scheduler.ts @@ -38,7 +38,6 @@ import { } from './units.ts'; import { type AttemptDeadlineMessage, - type FailureLimit, type OutputMessage, type PairStart, type WirePair, @@ -234,8 +233,8 @@ class SchedulerWorker { }); } - /** Sends a unit, with the run's failure limit when it has one, and starts tracking it. */ - dispatch(unit: WorkUnit, failureLimit: FailureLimit | undefined): void { + /** Sends a unit, saying whether the run has a failure limit, and starts tracking it. */ + dispatch(unit: WorkUnit, failureLimit: boolean): void { this.state = 'busy'; this.unit = unit; this.reported.clear(); @@ -256,7 +255,7 @@ class SchedulerWorker { file: unit.file, absolutePath: unit.absolutePath, pairs, - ...(failureLimit === undefined ? {} : { failureLimit }), + ...(failureLimit ? { failureLimit: true as const } : {}), }); } @@ -440,10 +439,9 @@ class Scheduler { this.wakeUp(); } - /** The failure limit a unit dispatched now carries, when the run has one. */ - private get failureLimit(): FailureLimit | undefined { - const limit = this.options.maxFailures; - return limit === undefined ? undefined : { limit, failures: this.failures }; + /** Whether the run has a failure limit, so its workers wait for an answer to each failure they report. */ + private get failureLimit(): boolean { + return this.options.maxFailures !== undefined; } /** Empties a target's queues, reporting every pair they held as skipped for `skip`. */ @@ -934,6 +932,12 @@ class Scheduler { } if (result.test.kind === 'setup') this.recordSetupOutcome(state, result); this.report(result); + // The worker waits for an answer to every failure it reports while + // the run has a limit. Below the limit it may go on; at the limit + // the interrupt the run is stopping with is its answer. + if (this.failureLimit && countsTowardFailureLimit(result.status) && !this.interrupting) { + worker.runner.send({ type: 'continue' }); + } break; } case 'serial-group': { diff --git a/packages/e2e/src/run/worker/protocol.ts b/packages/e2e/src/run/worker/protocol.ts index dfa5478d4..abb59bde6 100644 --- a/packages/e2e/src/run/worker/protocol.ts +++ b/packages/e2e/src/run/worker/protocol.ts @@ -85,18 +85,14 @@ export interface RunUnitMessage { readonly absolutePath: string; readonly pairs: readonly WirePair[]; /** - * The run's `--max-failures` and the failures it had counted when the unit - * was dispatched. The worker stops starting the unit's tests once its own - * failures reach the limit, without waiting for the runner's interrupt to - * arrive: by then it could have started the next test in the file. + * Set when the run has a `--max-failures` limit. Only the runner counts + * failures toward it, so after each result that counts the worker starts + * no further test until the runner answers: `continue` while the run is + * below the limit, `interrupt` once a failure reached it. One round-trip + * per failure: with several workers, two failures can land faster than any + * count the runner could send ahead. */ - readonly failureLimit?: FailureLimit; -} - -/** A run's failure limit and the failures counted toward it so far. */ -export interface FailureLimit { - readonly limit: number; - readonly failures: number; + readonly failureLimit?: true; } export interface InterruptMessage { @@ -133,13 +129,29 @@ export interface PingMessage { readonly type: 'ping'; } +/** + * The runner counted a failure the worker reported, and the run is still + * below its failure limit. Handled at once, like `ping`; see + * `RunUnitMessage.failureLimit`. + */ +export interface ContinueMessage { + readonly type: 'continue'; +} + /** The held step `holdId` names may run. Handled at once, like `ping`; an id the worker no longer holds is ignored. */ export interface StepReleaseMessage { readonly type: 'step-release'; readonly holdId: string; } -export type MainToWorker = RunUnitMessage | InterruptMessage | ShutdownMessage | TerminateMessage | PingMessage | StepReleaseMessage; +export type MainToWorker = + | RunUnitMessage + | InterruptMessage + | ShutdownMessage + | TerminateMessage + | PingMessage + | StepReleaseMessage + | ContinueMessage; export interface ReadyMessage { readonly type: 'ready'; diff --git a/packages/e2e/src/run/worker/session.ts b/packages/e2e/src/run/worker/session.ts index 9910851aa..8f907ad50 100644 --- a/packages/e2e/src/run/worker/session.ts +++ b/packages/e2e/src/run/worker/session.ts @@ -16,8 +16,8 @@ import { TargetExecutor, type InMemoryAttempts } from '../execute.ts'; import { encodeResult, type RunError } from '../records.ts'; import type { SessionStore } from '../sessions.ts'; import type { HeldStep, StepHolding } from '../step-hold.ts'; -import { countsTowardFailureLimit, disappearedResult, failureLimitSkip } from '../units.ts'; -import type { FailureLimit, MainToWorker, RunUnitMessage, WirePair, WorkerToMain } from './protocol.ts'; +import { countsTowardFailureLimit, disappearedResult } from '../units.ts'; +import type { MainToWorker, RunUnitMessage, WirePair, WorkerToMain } from './protocol.ts'; /** Pairs resolved locally for one unit, plus identities that vanished. */ export interface ResolvedUnitPairs { @@ -89,8 +89,12 @@ export class TargetWorker { get pairInFlight(): { readonly testId: string; readonly agent: string; readonly repeat: number } | undefined { return this.inFlight; } - /** The failure limit of the unit running now, counting this worker's own failures since its dispatch. */ - private failureLimit: FailureLimit | undefined; + /** Whether the run has a failure limit, so each failure this worker reports waits for the runner's answer. */ + private failureLimit = false; + /** Failures this worker reported that the runner has not answered yet. */ + private unanswered = 0; + /** Wakes the wait in `failuresAnswered` once the last of them is answered. */ + private answered: (() => void) | undefined; /** Serializes message handling so units never overlap on one worker. */ private queue: Promise = Promise.resolve(); /** Disposal happens once, whichever of shutdown or terminate asks first. */ @@ -125,14 +129,16 @@ export class TargetWorker { : { holdStep: (step: HeldStep, signal: AbortSignal) => this.holdStep(step, signal), heldScreens: deps.step === 'screen' }), ...(deps.debug !== undefined ? { debug: deps.debug } : {}), inMemory: deps.inMemory, + beforePair: () => this.failuresAnswered(), events: { onResult: (result) => { // Teardown after the result (an afterAll) belongs to no pair. if (this.inFlight?.testId === result.test.id && this.inFlight.agent === result.agent && this.inFlight.repeat === result.repeat) { this.inFlight = undefined; } + // Counted before it is sent: an in-process runner answers inside `emit`. + if (this.failureLimit && countsTowardFailureLimit(result.status)) this.unanswered += 1; this.host.emit({ type: 'result', result: encodeResult(result) }); - if (countsTowardFailureLimit(result.status)) this.countFailure(); }, onSerialGroup: (group) => this.host.emit({ type: 'serial-group', group }), onAttemptStart: (pair, index) => @@ -217,6 +223,11 @@ export class TargetWorker { // Now too: the unit it releases is the one running. this.holds.get(message.holdId)?.(); return; + case 'continue': + // Now too: the running unit is what waits for it. + this.unanswered = Math.max(0, this.unanswered - 1); + if (this.unanswered === 0) this.answered?.(); + return; default: message satisfies never; } @@ -249,18 +260,24 @@ export class TargetWorker { } /** - * Counts a failure toward the unit's failure limit. Reaching it stops the - * unit the way the runner's interrupt would, at once: the tests the worker - * has not started are skipped with the limit's reason, however long the - * runner's interrupt takes to arrive. Other workers' failures only add to - * the run's count, so a limit reached here is reached for the run too. + * Resolves once the runner has answered every failure this worker reported, + * or the interrupt arrived. The runner alone counts failures toward the + * run's limit, so a worker whose failure reached it never starts another + * test: the interrupt answering that failure skips the rest with the + * limit's reason. */ - private countFailure(): void { - const current = this.failureLimit; - if (current === undefined) return; - const counted = { limit: current.limit, failures: current.failures + 1 }; - this.failureLimit = counted; - if (counted.failures >= counted.limit) this.interruptController.abort(failureLimitSkip(counted.failures, counted.limit)); + private failuresAnswered(): Promise { + const signal = this.interruptController.signal; + if (this.unanswered === 0 || signal.aborted) return Promise.resolve(); + return new Promise((resolve) => { + const done = (): void => { + this.answered = undefined; + signal.removeEventListener('abort', done); + resolve(); + }; + this.answered = done; + signal.addEventListener('abort', done, { once: true }); + }); } /** @@ -294,7 +311,7 @@ export class TargetWorker { // fatal for the worker; the scheduler still holds the unit and synthesizes // failed results for every pair it never heard about. Reporting the unit // done first would clear that bookkeeping and drop those tests silently. - this.failureLimit = message.failureLimit; + this.failureLimit = message.failureLimit === true; const { pairs, missing, registration } = await deps.resolvePairs(message); for (const wire of missing) { executor.recordDisappeared( @@ -306,6 +323,7 @@ export class TargetWorker { // The imported registration has run nothing yet, so only the first // setup pair may adopt it; any later one needs its own fresh realm. for (const [index, pair] of pairs.entries()) { + await this.failuresAnswered(); await executor.runSetupUnit(pair, index === 0 ? registration : undefined); } } else { diff --git a/packages/e2e/tests/integration/parallel-workers.test.ts b/packages/e2e/tests/integration/parallel-workers.test.ts index 53f909e26..389d1a14a 100644 --- a/packages/e2e/tests/integration/parallel-workers.test.ts +++ b/packages/e2e/tests/integration/parallel-workers.test.ts @@ -867,6 +867,49 @@ test('would run last', async () => {}); 120_000, ); + it( + 'stops at --max-failures across workers: the worker whose failure reaches the limit starts no further test', + async () => { + // Each file fails first, then holds its worker in a long test. The file + // that fails later reaches the limit; its worker must wait for the + // runner's answer instead of starting its next test on a stale count. + const file = (name: string, failAfterMs: number) => `import { test } from 'e2e'; + +test('${name} fails', async ({ app }) => { + await app.open(); + await new Promise((resolve) => setTimeout(resolve, ${failAfterMs})); + throw new Error('${name}'); +}); +test('${name} next', async ({ app }) => { + await app.open(); + await new Promise((resolve) => setTimeout(resolve, 2_000)); +}); +test('${name} last', async () => {}); +`; + const { outcome, project } = await runProjectWithConfigFile( + { 'tests/a.e2e.ts': file('a', 0), 'tests/b.e2e.ts': file('b', 500) }, + { configSource: workerFakeConfigSource(2), runOptions: { maxFailures: 2 } }, + ); + expect(outcome.exitCode).toBe(1); + const failed = outcome.results.filter((result) => result.status === 'failed'); + expect(failed.map((result) => result.test.title).toSorted()).toEqual(['a fails', 'b fails']); + const endOf = (result: (typeof failed)[number]): number => { + const last = result.attempts.at(-1)!; + return Date.parse(last.startedAt) + last.durationMs; + }; + const tripping = failed.toSorted((a, b) => endOf(a) - endOf(b))[1]!.test.file; + const trippingRest = outcome.results.filter((result) => result.test.file === tripping && result.status !== 'failed'); + expect(trippingRest.map((result) => [result.status, result.skip?.cause, result.attempts.length])).toEqual([ + ['skipped', 'failure-limit', 0], + ['skipped', 'failure-limit', 0], + ]); + expect(outcome.results.filter((result) => result.status === 'interrupted').length).toBeLessThanOrEqual(1); + assertValidReport(outcome.report); + project.cleanup(); + }, + 120_000, + ); + it( 'reports a target whose workers cannot boot once, whatever the worker count', async () => { From e5f339a05337fab89bc08b49dbea63fdefcdb7c1 Mon Sep 17 00:00:00 2001 From: Mradul Singh Date: Fri, 13 Nov 2026 22:48:10 +0530 Subject: [PATCH 2/3] fix(run): cover continue below --max-failures and simplify the failure answer --- .changeset/max-failures-worker-wait.md | 1 - packages/e2e/src/run/execute.ts | 6 +-- packages/e2e/src/run/scheduler.ts | 33 +++++++-------- packages/e2e/src/run/worker/protocol.ts | 4 +- packages/e2e/src/run/worker/session.ts | 9 ++-- .../integration/parallel-workers.test.ts | 42 +++++++++++++++++-- packages/e2e/tests/unit/scheduler.test.ts | 17 ++++++++ 7 files changed, 77 insertions(+), 35 deletions(-) diff --git a/.changeset/max-failures-worker-wait.md b/.changeset/max-failures-worker-wait.md index 0033d2c0b..f6c310f6a 100644 --- a/.changeset/max-failures-worker-wait.md +++ b/.changeset/max-failures-worker-wait.md @@ -3,4 +3,3 @@ --- With several workers, `--max-failures` no longer lets the worker whose failure reaches the limit start its next test. That test was cancelled a moment later and reported `interrupted`; it is now skipped with cause `failure-limit`, as the docs say. -The runner alone counts failures toward the limit, and a worker waits for its answer to each failure before it starts another test. diff --git a/packages/e2e/src/run/execute.ts b/packages/e2e/src/run/execute.ts index 1e0842b5b..e3ae3cd7d 100644 --- a/packages/e2e/src/run/execute.ts +++ b/packages/e2e/src/run/execute.ts @@ -108,11 +108,7 @@ export interface TargetExecutorOptions extends EngineSessionsOptions { readonly holdStep?: ((step: HeldStep, signal: AbortSignal) => Promise) | undefined; /** Whether each hold reads the screen it starts on into `HeldStep.screen`. */ readonly heldScreens?: boolean | undefined; - /** - * Awaited before each pair of a file unit, ahead of the interrupt check: - * a worker holds its next test here until the runner has answered the - * failures it reported (see `RunUnitMessage.failureLimit`). - */ + /** Awaited before each pair starts, before the interrupt check. */ readonly beforePair?: (() => Promise) | undefined; readonly events?: ExecutionEvents; /** The virtual file of tests registered in memory, and the agents they run as; see `InMemoryAttempts`. */ diff --git a/packages/e2e/src/run/scheduler.ts b/packages/e2e/src/run/scheduler.ts index 1e4ec9a5f..0a87a575e 100644 --- a/packages/e2e/src/run/scheduler.ts +++ b/packages/e2e/src/run/scheduler.ts @@ -234,7 +234,7 @@ class SchedulerWorker { } /** Sends a unit, saying whether the run has a failure limit, and starts tracking it. */ - dispatch(unit: WorkUnit, failureLimit: boolean): void { + dispatch(unit: WorkUnit, answersFailures: boolean): void { this.state = 'busy'; this.unit = unit; this.reported.clear(); @@ -255,7 +255,7 @@ class SchedulerWorker { file: unit.file, absolutePath: unit.absolutePath, pairs, - ...(failureLimit ? { failureLimit: true as const } : {}), + ...(answersFailures ? { answersFailures: true as const } : {}), }); } @@ -403,16 +403,19 @@ class Scheduler { /** * Every result leaves through here, so the failure count is one number * however the result came about: a worker's verdict, a synthesized crash, - * or a skip. Reaching the limit stops the run at once. + * or a skip. Reaching the limit stops the run at once. Returns whether the + * result was a counted failure the run goes on after. */ - private report(result: ResultRecord): void { + private report(result: ResultRecord): boolean { this.options.events.onResult(result); - if (!countsTowardFailureLimit(result.status)) return; + if (!countsTowardFailureLimit(result.status)) return false; this.failures += 1; const limit = this.options.maxFailures; - if (limit === undefined || this.stopSkip !== undefined || this.failures < limit) return; - this.stopEarly(failureLimitSkip(this.failures, limit)); - this.options.events.onFailureLimit?.(this.failures, limit); + if (limit !== undefined && this.stopSkip === undefined && this.failures >= limit) { + this.stopEarly(failureLimitSkip(this.failures, limit)); + this.options.events.onFailureLimit?.(this.failures, limit); + } + return !this.interrupting; } /** @@ -440,7 +443,7 @@ class Scheduler { } /** Whether the run has a failure limit, so its workers wait for an answer to each failure they report. */ - private get failureLimit(): boolean { + private get answersFailures(): boolean { return this.options.maxFailures !== undefined; } @@ -672,7 +675,7 @@ class Scheduler { this.returnUnit(state, unit); return; } - if (worker.state === 'idle') worker.dispatch(unit, this.failureLimit); + if (worker.state === 'idle') worker.dispatch(unit, this.answersFailures); else worker.queued = unit; } } @@ -868,7 +871,7 @@ class Scheduler { worker.state = 'idle'; const queued = worker.queued; worker.queued = undefined; - if (queued !== undefined) worker.dispatch(queued, this.failureLimit); + if (queued !== undefined) worker.dispatch(queued, this.answersFailures); this.wakeUp(); break; } @@ -931,13 +934,7 @@ class Scheduler { worker.sawFailure = true; } if (result.test.kind === 'setup') this.recordSetupOutcome(state, result); - this.report(result); - // The worker waits for an answer to every failure it reports while - // the run has a limit. Below the limit it may go on; at the limit - // the interrupt the run is stopping with is its answer. - if (this.failureLimit && countsTowardFailureLimit(result.status) && !this.interrupting) { - worker.runner.send({ type: 'continue' }); - } + if (this.report(result) && this.answersFailures) worker.runner.send({ type: 'continue' }); break; } case 'serial-group': { diff --git a/packages/e2e/src/run/worker/protocol.ts b/packages/e2e/src/run/worker/protocol.ts index abb59bde6..32841039e 100644 --- a/packages/e2e/src/run/worker/protocol.ts +++ b/packages/e2e/src/run/worker/protocol.ts @@ -92,7 +92,7 @@ export interface RunUnitMessage { * per failure: with several workers, two failures can land faster than any * count the runner could send ahead. */ - readonly failureLimit?: true; + readonly answersFailures?: true; } export interface InterruptMessage { @@ -132,7 +132,7 @@ export interface PingMessage { /** * The runner counted a failure the worker reported, and the run is still * below its failure limit. Handled at once, like `ping`; see - * `RunUnitMessage.failureLimit`. + * `RunUnitMessage.answersFailures`. */ export interface ContinueMessage { readonly type: 'continue'; diff --git a/packages/e2e/src/run/worker/session.ts b/packages/e2e/src/run/worker/session.ts index 8f907ad50..632032a4e 100644 --- a/packages/e2e/src/run/worker/session.ts +++ b/packages/e2e/src/run/worker/session.ts @@ -90,7 +90,7 @@ export class TargetWorker { return this.inFlight; } /** Whether the run has a failure limit, so each failure this worker reports waits for the runner's answer. */ - private failureLimit = false; + private answersFailures = false; /** Failures this worker reported that the runner has not answered yet. */ private unanswered = 0; /** Wakes the wait in `failuresAnswered` once the last of them is answered. */ @@ -137,7 +137,7 @@ export class TargetWorker { this.inFlight = undefined; } // Counted before it is sent: an in-process runner answers inside `emit`. - if (this.failureLimit && countsTowardFailureLimit(result.status)) this.unanswered += 1; + if (this.answersFailures && countsTowardFailureLimit(result.status)) this.unanswered += 1; this.host.emit({ type: 'result', result: encodeResult(result) }); }, onSerialGroup: (group) => this.host.emit({ type: 'serial-group', group }), @@ -225,7 +225,7 @@ export class TargetWorker { return; case 'continue': // Now too: the running unit is what waits for it. - this.unanswered = Math.max(0, this.unanswered - 1); + this.unanswered -= 1; if (this.unanswered === 0) this.answered?.(); return; default: @@ -311,7 +311,7 @@ export class TargetWorker { // fatal for the worker; the scheduler still holds the unit and synthesizes // failed results for every pair it never heard about. Reporting the unit // done first would clear that bookkeeping and drop those tests silently. - this.failureLimit = message.failureLimit === true; + this.answersFailures = message.answersFailures === true; const { pairs, missing, registration } = await deps.resolvePairs(message); for (const wire of missing) { executor.recordDisappeared( @@ -323,7 +323,6 @@ export class TargetWorker { // The imported registration has run nothing yet, so only the first // setup pair may adopt it; any later one needs its own fresh realm. for (const [index, pair] of pairs.entries()) { - await this.failuresAnswered(); await executor.runSetupUnit(pair, index === 0 ? registration : undefined); } } else { diff --git a/packages/e2e/tests/integration/parallel-workers.test.ts b/packages/e2e/tests/integration/parallel-workers.test.ts index 389d1a14a..623ed9304 100644 --- a/packages/e2e/tests/integration/parallel-workers.test.ts +++ b/packages/e2e/tests/integration/parallel-workers.test.ts @@ -680,7 +680,7 @@ test('runs after the blocked tests', async ({ app }) => { assertValidReport(outcome.report); project.cleanup(); }, - 60_000, + 120_000, ); it( @@ -717,7 +717,7 @@ test('runs after the blocked retry', async () => {}); assertValidReport(outcome.report); project.cleanup(); }, - 60_000, + 120_000, ); it( @@ -751,7 +751,7 @@ test('times out and tears down slowly', { timeout: 1000 }, async ({ app }) => { expect(attempt.durationMs).toBeGreaterThan(6_000); project.cleanup(); }, - 60_000, + 120_000, ); it( @@ -787,7 +787,7 @@ test('outside the group', async () => {}); assertValidReport(outcome.report); project.cleanup(); }, - 60_000, + 120_000, ); it( @@ -873,6 +873,8 @@ test('would run last', async () => {}); // Each file fails first, then holds its worker in a long test. The file // that fails later reaches the limit; its worker must wait for the // runner's answer instead of starting its next test on a stale count. + // The 500 ms gap orders the two failures, so the tripping file is the + // one whose failure ended second. const file = (name: string, failAfterMs: number) => `import { test } from 'e2e'; test('${name} fails', async ({ app }) => { @@ -910,6 +912,38 @@ test('${name} last', async () => {}); 120_000, ); + it( + 'below --max-failures, each worker gets the runner\'s answer to its failure and runs its next test', + async () => { + // Both workers fail once and wait for the runner's `continue`; a lost + // answer would hold them forever, so both `next` tests must run. + const file = (name: string) => `import { test } from 'e2e'; + +test('${name} fails', async ({ app }) => { + await app.open(); + throw new Error('${name}'); +}); +test('${name} next', async ({ app }) => { + await app.open(); +}); +`; + const { outcome, project } = await runProjectWithConfigFile( + { 'tests/a.e2e.ts': file('a'), 'tests/b.e2e.ts': file('b') }, + { configSource: workerFakeConfigSource(2), runOptions: { maxFailures: 3 } }, + ); + expect(outcome.exitCode).toBe(1); + expect(outcome.results.map((result) => [result.test.title, result.status]).toSorted()).toEqual([ + ['a fails', 'failed'], + ['a next', 'passed'], + ['b fails', 'failed'], + ['b next', 'passed'], + ]); + assertValidReport(outcome.report); + project.cleanup(); + }, + 120_000, + ); + it( 'reports a target whose workers cannot boot once, whatever the worker count', async () => { diff --git a/packages/e2e/tests/unit/scheduler.test.ts b/packages/e2e/tests/unit/scheduler.test.ts index ce69a2329..0beb13c16 100644 --- a/packages/e2e/tests/unit/scheduler.test.ts +++ b/packages/e2e/tests/unit/scheduler.test.ts @@ -761,6 +761,23 @@ describe('failure limit', () => { expect(collected.failureLimits).toEqual([]); expect(fleet.interruptSkips).toEqual([]); }); + + it('answers each counted failure with continue below the limit, and with nothing at the limit or without one', async () => { + const target = makeTarget('web', 0); + const pairs = ['a', 'b', 'c'].map((name) => makePair(makeTest(`tests/${name}.e2e.ts`, name), target)); + const status = { [pairs[0]!.test.id]: 'timed-out' as const, [pairs[1]!.test.id]: 'failed' as const }; + const controlsWith = async (maxFailures: number | undefined): Promise => { + const fleet = new FakeFleet({ status }); + await run(makeSelection([{ target, pairs }]), makeCollection(pairs.map((pair) => pair.test.file), pairs), fleet, { + workers: 1, + ...(maxFailures === undefined ? {} : { maxFailures }), + }); + return fleet.controlMessages.filter((type) => type === 'continue' || type === 'interrupt'); + }; + expect(await controlsWith(3)).toEqual(['continue', 'continue']); + expect(await controlsWith(2)).toEqual(['continue', 'interrupt']); + expect(await controlsWith(undefined)).toEqual([]); + }); }); describe('time limit', () => { From 5516411c4fce96f8ff7d81f1503f86eedd1229ef Mon Sep 17 00:00:00 2001 From: Mradul Singh Date: Sat, 14 Nov 2026 04:13:15 +0530 Subject: [PATCH 3/3] test(run): restore the 60 s timeouts of four parallel-worker tests this change doesn't touch --- packages/e2e/tests/integration/parallel-workers.test.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/e2e/tests/integration/parallel-workers.test.ts b/packages/e2e/tests/integration/parallel-workers.test.ts index 623ed9304..18b8ef188 100644 --- a/packages/e2e/tests/integration/parallel-workers.test.ts +++ b/packages/e2e/tests/integration/parallel-workers.test.ts @@ -680,7 +680,7 @@ test('runs after the blocked tests', async ({ app }) => { assertValidReport(outcome.report); project.cleanup(); }, - 120_000, + 60_000, ); it( @@ -717,7 +717,7 @@ test('runs after the blocked retry', async () => {}); assertValidReport(outcome.report); project.cleanup(); }, - 120_000, + 60_000, ); it( @@ -751,7 +751,7 @@ test('times out and tears down slowly', { timeout: 1000 }, async ({ app }) => { expect(attempt.durationMs).toBeGreaterThan(6_000); project.cleanup(); }, - 120_000, + 60_000, ); it( @@ -787,7 +787,7 @@ test('outside the group', async () => {}); assertValidReport(outcome.report); project.cleanup(); }, - 120_000, + 60_000, ); it(