Skip to content

test: avoid truncating watched worker deps#63083

Open
inoway46 wants to merge 1 commit into
nodejs:mainfrom
inoway46:fix-test-watch-mode-worker
Open

test: avoid truncating watched worker deps#63083
inoway46 wants to merge 1 commit into
nodejs:mainfrom
inoway46:fix-test-watch-mode-worker

Conversation

@inoway46
Copy link
Copy Markdown
Contributor

@inoway46 inoway46 commented May 2, 2026

This fixes a flaky sequential/test-watch-mode-worker failure where the nested CJS worker dependency case can log {} instead of sub-dep v1.

The test rewrites watched worker dependency files to trigger --watch restarts, but default writeFileSync() temporarily truncates the file. A restarted worker can read the dependency during that empty-file window.

This change keeps the write-based restart trigger, but uses r+ to overwrite without truncation.

Reported in: https://github.com/nodejs/reliability/blob/main/reports/2026-05-02.md

not ok 5323 sequential/test-watch-mode-worker
  ---
  Test failure: 'should watch changes to nested worker dependencies - cjs'
  AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal:
    [
      'sub-dep v1',
      "Completed running '/home/iojs/node-tmp/.tmp.5322/2.js'. Waiting for file changes before restarting...",
      "Restarting '/home/iojs/node-tmp/.tmp.5322/2.js'",
  +   '{}',
  -   'sub-dep v1',
      "Completed running '/home/iojs/node-tmp/.tmp.5322/2.js'. Waiting for file changes before restarting..."
    ]

Testing:

$ ./tools/test.py sequential/test-watch-mode-worker

$ ./tools/test.py -j1 --repeat 20 sequential/test-watch-mode-worker

Refs: #62368

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. test Issues and PRs related to the tests. labels May 2, 2026
@inoway46 inoway46 force-pushed the fix-test-watch-mode-worker branch from b27b615 to da136db Compare May 2, 2026 14:44
@inoway46 inoway46 changed the title test: fix flaky test-watch-mode-worker test: avoid truncating watched worker deps May 2, 2026
Signed-off-by: inoway46 <inoueyuya416@gmail.com>
@inoway46 inoway46 force-pushed the fix-test-watch-mode-worker branch from da136db to cfcd3e7 Compare May 2, 2026 14:54
@inoway46 inoway46 marked this pull request as ready for review May 2, 2026 14:57
@codecov
Copy link
Copy Markdown

codecov Bot commented May 2, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.65%. Comparing base (13e90d0) to head (cfcd3e7).
⚠️ Report is 126 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #63083      +/-   ##
==========================================
- Coverage   91.49%   89.65%   -1.84%     
==========================================
  Files         360      712     +352     
  Lines      151674   220498   +68824     
  Branches    23919    42278   +18359     
==========================================
+ Hits       138772   197685   +58913     
- Misses      12625    14664    +2039     
- Partials      277     8149    +7872     

see 475 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.

@GrinZero
Copy link
Copy Markdown
Contributor

GrinZero commented May 9, 2026

LGTM

@inoway46
Copy link
Copy Markdown
Contributor Author

A newer reliability failure shows a different failure log for the same test:
https://github.com/nodejs/reliability/blob/main/reports/2026-05-11.md

not ok 5567 sequential/test-watch-mode-worker
  ---
  Test failure: 'should watch changes to worker - cjs'
  AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal:
    [
      'worker running',
      "Completed running '/home/iojs/node-tmp/.tmp.5566/0.js'. Waiting for file changes before restarting...",
      "Restarting '/home/iojs/node-tmp/.tmp.5566/0.js'",
  -   'worker running',
      "Completed running '/home/iojs/node-tmp/.tmp.5566/0.js'. Waiting for file changes before restarting..."
    ]

This is consistent with the same truncate-window race: the watched worker entry file can be observed while temporarily truncated, so the restarted worker exits without printing worker running.

@inoway46
Copy link
Copy Markdown
Contributor Author

Could someone please request CI?

@inoway46
Copy link
Copy Markdown
Contributor Author

@MoLow
Sorry for the mention. This flake still appears several times, so could you please request a full CI?
Ref: nodejs/reliability#1542

@lpinca lpinca added the request-ci Add this label to start a Jenkins CI on a PR. label May 16, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. label May 16, 2026
@nodejs-github-bot
Copy link
Copy Markdown
Collaborator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-ci PRs that need a full CI run. test Issues and PRs related to the tests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants