Flaky: daemon-update-status.test.js 'temp names differ every write' fails when the pid's digits appear in the random temp name

Open Beginner friendly
#9,277 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
1/5
Estimated time
Under an hour
Newbie friendliness
88/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
javascript, node.js
Domain
testing

Research direction

The assertion is at packages/server/tests/daemon-update-status.test.js:444 in 'temp names differ every write'; read it beside writeFileAtomic in src/utils/small-file.js to see what the name looks like. Replace the p.includes(String(process.pid)) check with a basename match: x.json.tmp- plus exactly sixteen hex characters, the two names differ, and neither is the old predictable name. Run node --test --test-name-pattern 'temp names differ every write' packages/server/tests/daemon-update-status.test.js; done when it passes and still fails after reverting writeFileAtomic to a fixed name.

Written by the indexing model from the issue text.

Description

priority: low server testing

Context

Filed from: #9273

Seen in CI on PR #9273, whose diff touches only packages/server/tests/freshness/ and cannot reach this file.

Symptom

Server Windows Tests failed once with a single failing test out of 15,915:

# Subtest: temp names differ every write
not ok 3 - temp names differ every write
  location: '...\\packages\\server\\tests\\daemon-update-status.test.js:428:3'
  error: 'no pid in the name'
  code: 'ERR_ASSERTION'
  expected: true
  actual: false
not ok 985 - writes use unpredictable temp names (#8331)

Failing job. Every other check on that head passed, including Server Tests on Linux. The same check passed on main before and after, and on the three earlier pull requests that touched the same directory.

Cause

Read from the code; the log does not print the process id or the temp names, so the exact collision was not observed.

tests/daemon-update-status.test.js:444 asserts on the whole path:

assert.ok(seen.every((p) => !p.includes(String(process.pid))), 'no pid in the name')

Each path is <tmpdir>/chroxy-update-status-XXXXXX/x.json.tmp-<16 hex characters>: six random characters from mkdtempSync and sixteen from randomBytes(8).toString('hex') in src/utils/small-file.js (writeFileAtomic). The assertion fails whenever the digits of the process id happen to appear anywhere in those random characters, or in the temp directory's own path. writeFileAtomic does not put the process id in the name, so the failure says nothing about the code under test.

How often depends on the length of the process id. A quick simulation of the random part alone gives about 0.5% of runs for a three-digit id, 0.04% for four digits and 0.003% for five. The check runs on every pull request on Linux and on Windows.

What to change

Assert on the shape of the name instead of searching the path for digits. For example: the basename matches x.json.tmp- followed by exactly sixteen hex characters, the two names differ, and neither equals the old predictable name this test was written to rule out. That keeps the intent (no predictable temp name) without depending on which digits the random bytes produce.

Acceptance Criteria

  • temp names differ every write cannot fail because of the process id's digits appearing in a random suffix or in the temp directory path
  • The test still fails if writeFileAtomic goes back to a predictable temp name (shown once by reverting the helper locally)
  • Server Tests and Server Windows Tests pass
Dominant language
JavaScript
Stars
7
Forks
1
Avg merge
2h 19m
Merged PRs (30d)
263

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from blamechris/chroxy

All issues in blamechris/chroxy

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.