Skip to content

onTestRunEnd receives reason: 'passed' when a forks worker is killed and its test file never completes #11464

Closed

Description

@prestonwillis10

Describe the bug

When a forks worker dies before its test file finishes, onTestRunEnd still receives reason: 'passed'. The dead file is left in pending state and the summary reads Test Files 1 passed (2). The run exits 1 only because of the unhandled pool error — a reporter that looks at reason, or a config with dangerouslyIgnoreUnhandledErrors: true, sees a passed run in which a planned file never executed.

Reproduction

Two test files and a config (npm i vitest@5.0.3, npx vitest run):

// passing.test.ts
import { test, expect } from 'vitest'
test('passes', () => { expect(1).toBe(1) })

// self-kill.test.ts  — stands in for an OOM kill or a host signal
import { test } from 'vitest'
test('kills its own forks worker', () => { process.kill(process.pid, 'SIGKILL') })

// vitest.config.ts
import { defineConfig } from 'vitest/config'
export default defineConfig({
  test: {
    pool: 'forks',
    reporters: ['default', {
      onTestRunEnd(modules, errors, reason) {
        console.log(`reason=${reason} errors=${errors.length} ` +
          modules.map(m => `${m.moduleId.split('/').pop()}:${m.state()}`).join(' '))
      },
    }],
  },
})

Output (vitest 5.0.3, Node 24.14.0, Linux x64; same on 4.1.10):

Caused by: Error: Worker exited unexpectedly with signal SIGKILL during started state while running test file .../self-kill.test.ts
 Test Files  1 passed (2)
reason=passed errors=1 passing.test.ts:passed self-kill.test.ts:pending

Expected

A run in which a test module never completed is not reported to onTestRunEnd as 'passed' — either a distinct reason (e.g. 'failed', or a new value), or the unexecuted module ending in a non-pending failure state. Either lets a reporter or CI gate tell "all files ran" from "a worker died".

Workaround

A custom reporter that diffs the planned module list against those that reached a terminal state and fails the run itself.

Not covered by

#8766/#8767 (RPC torn down too soon, fixed 4.0.1), #8861/#8967 (Windows Defender, fixed 4.0.8), #9762 (bun/glibc). The exit-signal reporting (with signal SIGKILL … while running test file) is already present in 5.x; this is only about the run-end reason.

Activity

  1. ezefernandezyf commented on Oct 5, 2026

    @ezefernandezyf
    Contributor

    I reproduced this. Two test files with pool: 'forks' and a reporter that prints what
    onTestRunEnd receives; one of them calls process.kill(process.pid, 'SIGKILL'):

    >>> reason=passed errors=1 passing.test.ts:passed self-kill.test.ts:pending
    

    The crashed file stays pending, it never ran a test, so ok() reports no failure. The error
    was in unhandledErrors the whole time, the reason just never looked there. end() computed
    it with hasFailed(modules) only, which is why a run that fails with an unhandled error is
    still reported as passed, contradicting both the documented TestRunEndReason values
    (passed: "there are no errors") and the exit code.

    I have a tested fix. The reason now comes from the same rule that decides whether the run
    fails, so it cannot disagree with the exit code, and dangerouslyIgnoreUnhandledErrors is
    honored. test/e2e/test/pool-worker-exit.test.ts has a case that fails without the change
    (expected 'passed' to be 'failed') and passes with it. It is in #11498, which the pull
    request policy closed automatically.

  2. locked and limited conversation to collaborators on Oct 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions