Skip to content

test(js): drive the remaining fake-timer tests through Manual - #7076

Merged
kixelated merged 3 commits into
mainfrom
quest/m0/test-flakes-2/fake-timers
Oct 29, 2026
Merged

kixelated merged 3 commits into
mainfrom
quest/m0/test-flakes-2/fake-timers

Conversation

@kixelated

@kixelated kixelated commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator

Finishes quest/m0/test-flakes-2/fake-timers.md.

Problem

The last @moq/net and @moq/hang tests on bun's jest.useFakeTimers() drained work with hand-rolled loops (64 microtask turns, 20 setImmediate turns, or one MessageChannel task). Neither fake timers nor those loops can see a host-task yield, so the tests passed only because nothing yielded at the wrong moment.

Changes

Each test installs a Manual clock and closes it when it finishes (in afterEach, finally, onTestFinished, or using), so no clock leaks into the next test. clock.advance(...) replaces jest.advanceTimersByTime plus its drain loop, and clock.advance(Nano.zero) replaces the drain on its own.

  • connection/forward.test.ts: the whole file.
  • ietf/publisher.test.ts: the clustered tests (clustered() now owns the clock), plus two epoch tests that shared their flush/take helpers.
  • ietf/subscriber.test.ts: "returning demand preserves pending setup".
  • lite/subscriber.test.ts: the three setup-deadline tests.
  • lite/publisher.test.ts: the PROBE Report test, plus the malformed SUBSCRIBE_UPDATE test that shared its settleControls drain.
  • integration.test.ts: "a request outlives the listing it resolved through" runs on Manual from the start. It no longer switches fake timers on and off mid-test, and expect(ended).toBe(1) replaces a wall-clock poll.
  • connection/connect.test.ts: "SETUP preserves a delayed session close code".
  • hang/src/container/consumer.startup.test.ts: setup() owns the clock and returns flush.
  • test/audio-quality/clients/js/src/probe.test.ts: already used Manual. Drops its redundant jest.useFakeTimers() and its private import of js/clock/src/host.ts's drain.

Together with moq-dev/moq#6988, which converts pool.test.ts and stats.test.ts, no useFakeTimers or advanceTimersByTime is left in the repo.

forward.test.ts's "a watch arriving as the linger expires opens a fresh request" was vacuous. With fake timers it still passed after removing the linger callback's eager interests.delete(prefix), which is the behavior it names. A plain Manual port can't place the watch at that moment either: jump lands it before the callback, and advance lands it after the stream wound down. FakeSession now has an onClose hook, so the test opens the watch exactly as the forwarder closes the old request. The test fails without that delete.

Verification

  • just check passes.
  • Each converted test fails when its behavior breaks (mutations applied and reverted, not committed):
    • forward.ts: LINGER ±1ms, and the eager interests.delete.
    • ietf/publisher.ts: the advertise timeout, the refusal's retry interval, and the backoff doubling and wait.
    • util/deadline.ts: REQUEST_TIMEOUT_MS and the deadline's stream aborts.
    • lite/publisher.ts: PROBE_INTERVAL.
    • error.ts: sessionCause reporting the session's close.
    • forward.ts again for the integration test: LINGER, and the hold-beneath check.
    • hang/consumer.ts: the hole-elapsed and skip-hole checks.
    • The audio probe's SAMPLE_INTERVAL_MS.
  • Merged with moq-dev/moq#6988 and with Budget.poll forced to yield on every call, every converted file passes. They also pass with that PR's Manual yield accounting disabled, so none of them races a yield today. This change is preventive, as the quest expected.
  • This branch merges cleanly with fix(js): yield host tasks through the injected clock #6988 in either order.

Impact

Public API: none. Wire: none. Tests only.

Choices made without asking

  • Kept independent of moq-dev/moq#6988 instead of stacking on it. Everything here uses Manual APIs already on main, and the two branches merge cleanly. Stacking would have put fix(js): yield host tasks through the injected clock #6988's unreviewed diff in this PR. The converted tests start seeing yields once fix(js): yield host tasks through the injected clock #6988 lands.
  • Converted the hand-rolled drains next to the fake-timer tests (two ietf publisher epoch tests and lite publisher's malformed SUBSCRIBE_UPDATE). They shared those helpers and could not see a yield either. I also cleaned up the audio-quality probe test, which is outside the two packages the quest named.
  • Rewrote the linger-race test with a close hook (see Changes) instead of porting it as-is.
  • In the ietf subscriber test, the 6s step before first.close() is now await clock.advance(...), which drains, instead of a synchronous jump. The test and its timeout mutation still behave the same.
  • Inlined the ietf publisher's flush/advance helpers into clock.advance(...), which the rest of that file already uses.

Follow-ups

  • broadcast.test.ts "a stalled consumer does not pin evicted groups" has an inert time step. It moves wall time with setSystemTime, but the cache ages groups on the monotonic clock (Timestamp.now() reads now(), and setSystemTime does not move performance.now()). The test passes with the setSystemTime(new Date(12_000)) line removed. It should drive a Manual clock past maxAge, and be shown to fail when eviction breaks. track.test.ts's setSystemTime use is intentional: it proves wall-clock changes don't affect the budget.
  • Seen once in a local just check on main: "a server refuses a client offering only IETF versions in the moql SETUP" failed. fix(js): yield host tasks through the injected clock #6988 already fixes it.

🤖 Generated with Claude Code

(Written by Claude Opus 5.5)

kixelated and others added 2 commits October 28, 2026 03:04
Bun's fake timers cannot see a host-task yield, so these tests passed
only while nothing yielded at the wrong moment. They now install a
Manual clock and restore the ambient one when they finish.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated kixelated changed the title JS tests drive time through Manual test(js): drive the remaining fake-timer tests through Manual Oct 28, 2026
@kixelated
kixelated marked this pull request as ready for review October 28, 2026 10:27
@coderabbitai

coderabbitai Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 14 seconds.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c211b294-3c30-4805-a667-cc18e40b14ae
Commits

Reviewing files that changed from the base of the PR and between 5df6b85 and 4dc0980.

Files selected for processing: 11
  • js/hang/src/container/consumer.startup.test.ts
  • js/net/src/connection/connect.test.ts
  • js/net/src/connection/forward.test.ts
  • js/net/src/ietf/publisher.test.ts
  • js/net/src/ietf/subscriber.test.ts
  • js/net/src/integration.test.ts
  • js/net/src/lite/publisher.test.ts
  • js/net/src/lite/subscriber.test.ts
  • quest/m0/test-flakes-2/README.md
  • quest/m0/test-flakes-2/fake-timers.md
  • test/audio-quality/clients/js/src/probe.test.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-29T03:25:30.212452Z 4dc0980 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@kixelated kixelated left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review by review (OpenAI)

Reviewed commit: 5b4abe3

No actionable bugs found. Reusing Manual.advance instead of fixed drain loops is a simpler, more deterministic direction; the explicit close hook meaningfully exercises the linger-expiry reentrancy window. Clock restoration and the converted deadline/backoff assertions look consistent with the surrounding implementations. Host-yield accounting still depends on #6988 as documented, rather than being implemented here.

Verification: static inspection of the changed tests and relevant clock/forwarding/deadline helpers, including an independent lifecycle pass. I did not run tests, mutation checks, or the claimed forced-yield integration checks.

@kixelated

Copy link
Copy Markdown
Collaborator Author

Merged main into the branch (4dc0980) to clear one conflict in js/net/src/integration.test.ts. On main, "a request outlives the listing it resolved through" now loops over request/follow instead of announced: false/true. I kept main's loop and test name and added this PR's Manual install and onTestFinished close, so both variants run on Manual. Codex re-reviewed the new head with no findings (👍).

  • just check origin/main passes: @moq/net 2588, @moq/hang 311, @moq/audio-quality 36, 0 failures.
  • quest check passes.
  • useFakeTimers/advanceTimersByTime remain only in pool.test.ts and stats.test.ts, which moq-dev/moq#6988 converts.

Stress run of connect.test.ts under load: 20 runs of that file alone, each alongside two full @moq/net suites, all passed (44/44). Across the 40 full-suite load runs, "a server refuses a client offering only IETF versions in the moql SETUP" failed once (1/40). Bun printed the raw no common version found; client offered: ff00000e error from accept.ts:187, not an expect(...).rejects mismatch. That suggests accepting rejects during the test's Stream.open/encode awaits, before .rejects attaches a handler, so it's a race in that test rather than a fake-timer leak. This PR changes only a different test in that file, which now closes its clock in finally. Left as a follow-up.

(Written by Claude Opus 5.5)

@kixelated
kixelated added this pull request to the merge queue Oct 29, 2026
Merged via the queue into main with commit f94ae72 Oct 29, 2026
11 checks passed
@kixelated
kixelated deleted the quest/m0/test-flakes-2/fake-timers branch October 29, 2026 03:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant