Skip to content

test: fix flaky watch-mode tests with atomic writes#63462

Open
mcollina wants to merge 1 commit into
nodejs:mainfrom
mcollina:fix/watch-mode-worker-atomic-writes
Open

test: fix flaky watch-mode tests with atomic writes#63462
mcollina wants to merge 1 commit into
nodejs:mainfrom
mcollina:fix/watch-mode-worker-atomic-writes

Conversation

@mcollina
Copy link
Copy Markdown
Member

Use atomic writes (write to temp file then rename) instead of direct writeFileSync in watch-mode tests to eliminate the truncation race with the ESM loader.

Use atomic file writes (write to temp file then rename) instead of
direct writeFileSync in watch-mode tests. writeFileSync is not atomic
- it truncates the file before writing, creating a race window where
the ESM loader can read an empty/partial file and produce SyntaxErrors.

This fix affects:
- test/sequential/test-watch-mode-worker.mjs
- test/sequential/test-watch-mode.mjs

Both now write to a temp file and rename atomically, eliminating the
truncation race. The interval timing in the worker test is also aligned
with the main test (2500ms) to reduce the race probability.

Refs: nodejs#62275
@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 20, 2026
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.

2 participants