Skip to content

test: deflake test-runner-coverage - #65728

Open
christianaurichzm wants to merge 1 commit into
nodejs:mainfrom
christianaurichzm:deflake-test-runner-coverage
Open

test: deflake test-runner-coverage#65728
christianaurichzm wants to merge 1 commit into
nodejs:mainfrom
christianaurichzm:deflake-test-runner-coverage

Conversation

@christianaurichzm

Copy link
Copy Markdown
Contributor

test-runner-coverage is marked flaky on Windows, Linux s390x and AIX. Every recorded failure is the same assertion:

AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:

  assert(!findCoverageFileForPid(result.pid))

Cause

The two subtests that pass NODE_V8_COVERAGE: tmpdir.path leave a coverage-<pid>-<ts>-<n>.json file behind, and tmpdir.refresh() only runs once, at the top of the file. The nine later checks spawn without NODE_V8_COVERAGE, so their coverage goes to the private mkdtemp directory that setupCoverage() creates and cleanup() removes, never to the test tmpdir. findCoverageFileForPid() keys only on the pid, so a match can only come from that stale file, once the OS hands the same pid to a later child.

Reproduction

Forcing pid reuse inside a pid namespace reproduces it on Linux x64. Pushing the cursor past RESERVED_PIDS makes the kernel allocate cyclically within [300, pid_max), a window this test wraps through several times:

unshare -rpf --mount-proc bash -ec '
  echo 350 > /proc/sys/kernel/pid_max
  cat /proc/sys/kernel/pid_max          # verify the requested value took effect
  for i in $(seq 1 320); do /bin/true; done
  out/Release/node test/parallel/test-runner-coverage.js'
result
without the patch 40/40 runs failed
with the patch 0/40 runs failed

tools/test.py --repeat=24 -J parallel/test-runner-coverage passes on a normal Linux x64 run either way.

Fix

Refresh the tmpdir from an after() hook on each subtest that dumps into it. The hook rather than a trailing call matters: if an assertion in one of those subtests fails, a trailing cleanup is skipped and the stale file turns every later check into a second, misleading failure. Same forced pid reuse, with the failure injected into the last dumping subtest:

cascading failures
cleanup at end of subtest 20/20 runs
cleanup in after() 0/20 runs

This also drops the PASS, FLAKY entries added in #65562 as a stopgap "while the stale coverage-file behavior is investigated"; with the stale file gone that failure path is removed, and keeping the entries would hide a regression
on those platforms.

Needs a full CI run to reach the affected configurations. The GitHub Actions Windows coverage job sets NODE_V8_COVERAGE for the test step, so it does not exercise this path.

Fixes: #55154

The subtests that set NODE_V8_COVERAGE leave a coverage-<pid>-*.json
file in the test tmpdir, and nothing removes it. The later subtests
spawn without NODE_V8_COVERAGE, so their coverage goes to a private
mkdtemp directory that is removed on cleanup rather than to the test
tmpdir. A match in findCoverageFileForPid(result.pid) can therefore only
come from a stale file whose pid has been reused, which is why the
failures are only reported on platforms that recycle pids quickly.

Refresh the tmpdir from an after() hook on each subtest that dumps into
it, so a failure in one of them cannot leave the file behind and turn
every later check into a second, misleading failure. Drop the flaky
designations.

Fixes: nodejs#55154
Signed-off-by: Christian Aurich <christian.aurichzm@gmail.com>
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/test_runner

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. test Issues and PRs related to Node.js core tests and test infrastructure. labels Sep 1, 2026
@codecov

codecov Bot commented Sep 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.11%. Comparing base (f9ab994) to head (4d8c8c3).
⚠️ Report is 10 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #65728      +/-   ##
==========================================
+ Coverage   90.07%   90.11%   +0.03%     
==========================================
  Files         754      754              
  Lines      256395   256395              
  Branches    48494    48523      +29     
==========================================
+ Hits       230947   231044      +97     
+ Misses      16563    16479      -84     
+ Partials     8885     8872      -13     

see 32 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@atlowChemi atlowChemi added the request-ci Add this label to start a Jenkins CI on a PR. label Sep 2, 2026
@panva panva added the author ready PRs with CI started, the required approvals, and no outstanding review comments. label Sep 2, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Sep 2, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@trivikr

trivikr commented Sep 2, 2026

Copy link
Copy Markdown
Member

@trivikr trivikr added the flaky-test Issues and PRs involving tests that fail intermittently in CI. label Sep 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author ready PRs with CI started, the required approvals, and no outstanding review comments. flaky-test Issues and PRs involving tests that fail intermittently in CI. needs-ci PRs that need a full CI run. test Issues and PRs related to Node.js core tests and test infrastructure.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

parallel/test-runner-coverage is flaky

5 participants