Skip to content

test(solid): deterministic clock in client-recovery-record.spec.ts - #3635

Merged
ryansolid merged 1 commit into
nextfrom
test/deflake-client-recovery-record
Sep 24, 2026
Merged

ryansolid merged 1 commit into
nextfrom
test/deflake-client-recovery-record

Conversation

@ryansolid

Copy link
Copy Markdown
Member

The flake

packages/solid/test/client-recovery-record.spec.ts — "a fragment already rejected at hydration: no wait, a fresh render" — asserted waitedMs < 5 on the wall clock. waitedMs is the delta between two performance.now() reads inside the runtime: one at boundary registration (registeredAt, read only when a "recovery" listener exists) and one when the queued recover microtask fires. That hop covers the rest of the createRoot body, a flush(), and the microtask checkpoint — sub-millisecond locally, but on the coverage-instrumented CI job under load it read:

Each time the failed assertion also skipped the test's own off(), so the "recovery" listener leaked into the following test, "with no listener the boundary still recovers, and nothing is recorded", whose observed("recovery") === false check then failed with expected true to be false. Reproduced locally by inserting a 6ms synchronous stall between boundary() and the await: same two failures, same lines.

The fix (test only)

  • performance.now() is a scripted clock via vi.spyOn (the test(web): run the performance-tracks spec on a controllable engine clock #3598 pattern, as in attribution-interactions.test.ts): it stands still unless the test moves it, so every duration is asserted exactly instead of against a threshold.
    • already rejected at hydration → waitedMs: 0 (the clock never moves between registration and recovery — the person saw no fallback)
    • rejects while streaming → the test advances the clock by 30 before rejecting → waitedMs: 30
    • rendering the children advances the clock by 2 → renderMs: 2 in both, proving the fresh render sits between the runtime's last two reads
    • no listener → performance.now is asserted never called (the doc comment's "no listener, no clock read")
  • The "recovery" subscription is stored module-level and torn down in afterEach alongside vi.restoreAllMocks(), so an assertion failure can no longer cascade into the next test.

Real timers still drive the promise settles; only the stamps are the test's. Verified: spec 20/20 green in a loop; the stall no longer affects the result; a forced failure in test 2 leaves test 4 green; full solid-js suite (780) and the @solidjs/web client suite native + JSX_COMPILER=babel (944 each) pass.

Public API

None.

— Claude via Cursor

The "already rejected at hydration" case asserted `waitedMs < 5` on the
wall clock. `waitedMs` is the delta between two `performance.now()`
reads in the runtime — at boundary registration and when the queued
`recover` microtask runs — and on a loaded, coverage-instrumented CI
worker that hop read 5.3ms, 7.3ms and 13.3ms today. A failed assertion
also skipped the test's own `off()`, leaking the listener into the next
test, whose `observed("recovery") === false` check then failed too.

`performance.now()` is now a scripted clock (the #3598 pattern): it
stands still unless the test moves it, so every duration is asserted
exactly — `waitedMs: 0` for the already-rejected case, `30` for the
streaming case where the test advances the clock before rejecting, and
`renderMs: 2` because rendering the children advances it by 2. The
subscription is torn down in `afterEach`, so a failure cannot cascade.
@changeset-bot

changeset-bot Bot commented Sep 24, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 0f25448

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coveralls

Copy link
Copy Markdown

Coverage Report for CI Build 35984972807

Coverage remained the same at 73.134%

Details

  • Coverage remained the same as the base build.
  • Patch coverage: No coverable lines changed in this PR.
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 1142
Covered Lines: 883
Line Coverage: 77.32%
Relevant Branches: 894
Covered Branches: 606
Branch Coverage: 67.79%
Branches in Coverage %: Yes
Coverage Strength: 25.34 hits per line

💛 - Coveralls

@codspeed

codspeed Bot commented Sep 24, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 176 untouched benchmarks
⏩ 3 skipped benchmarks1


Comparing test/deflake-client-recovery-record (0f25448) with next (974506c)

Open in CodSpeed

Footnotes

  1. 3 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@ryansolid
ryansolid merged commit 1b1152e into next Sep 24, 2026
7 checks passed
@ryansolid
ryansolid deleted the test/deflake-client-recovery-record branch September 24, 2026 10:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants