Skip to content

make two timing-dependent bus-core tests deterministic - #365

Open
adenhertog wants to merge 3 commits into
masterfrom
chore-flaky-timing-tests
Open

adenhertog wants to merge 3 commits into
masterfrom
chore-flaky-timing-tests

Conversation

@adenhertog

@adenhertog adenhertog commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Make two timing-dependent bus-core tests deterministic so they stop failing on loaded CI runners.

Background

The dispatcher spec "when it is stopped after a send timed out" failed on CircleCI build 1359 (stop() took 28 ms, expected at least 30 ms). workflow/started.spec.ts sleeps 2 s per step inside a 5 s beforeAll timeout.

Problem

  • The dispatcher test measured how long stop() took after polling for the timeout warning every 5 ms, so less time was left on a busy runner.
  • started.spec.ts slept a fixed 2 s after each message, which can exceed the test timeout in a loaded full run with coverage.

Approach

  • The slow send now waits on a promise the test controls. The test asserts stop() hasn't resolved while that send is pending, releases it, and asserts stop() then resolves.

  • started.spec.ts uses an InMemoryQueue and await queue.idle() instead of sleep.

  • The dispatcher's "started with a periodic task" test (failed on build 1371) and its "told a message was scheduled" test use Jest fake timers and a fixed jitter, asserting what ran at exact points in time instead of measuring real elapsed time.

  • "when sending is paused and there is nothing to probe" and "when probes keep failing" also use fake timers, so their pause gaps are exact (including the wake timer's 1 ms margin) instead of real-time upper bounds.

  • "stopped after a send timed out" now samples whether stop() resolved right after the send finished, so it fails if stop() waits the full sendTimeoutMs.

  • Tests only. The dispatcher spec passed 20 runs in a loop; unit suite, lint and format check pass.

  • This is original work under the clean-room policy, not ported, translated or copied from another messaging framework

  • No changeset needed (tests only, no user-facing change)

  • Docs: none needed (tests only)

🤖 Generated with Claude Code

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@adenhertog adenhertog added the no-issue PR not tied to a roadmap issue label Oct 25, 2026
adenhertog and others added 2 commits October 25, 2026 20:56
… tests

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

This branch has not been deployed

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

Labels

no-issue PR not tied to a roadmap issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant