Skip to content

Fix race condition in Time.test.ts timing assertions#18

Merged
miccy merged 2 commits intosync/bun-migrationfrom
copilot/sub-pr-5-yet-again
Feb 3, 2026
Merged

Fix race condition in Time.test.ts timing assertions#18
miccy merged 2 commits intosync/bun-migrationfrom
copilot/sub-pr-5-yet-again

Conversation

Copy link
Copy Markdown

Copilot AI commented Feb 3, 2026

The Time.test.ts test was failing intermittently in CI (webkit browser) due to a timing race condition in the assertion logic.

Root Cause

The test captured Date.now() after creating the time object, then called time.now() twice and asserted both values were within [now - 10, now + 10]. If enough execution time elapsed between the reference capture and the second call, the assertion would fail.

// Before (flaky)
const time = createTime();
const now = Date.now();
expect(time.now()).toBeGreaterThanOrEqual(now - 10);
expect(time.now()).toBeLessThanOrEqual(now + 10);  // Can fail if time progresses

// After (stable)
const before = Date.now();
const time = createTime();
const after = Date.now();
const timeNow = time.now();
expect(timeNow).toBeGreaterThanOrEqual(before - 10);
expect(timeNow).toBeLessThanOrEqual(after + 10);  // Proper time window

Changes

  • Capture timestamps before and after createTime() to establish proper time window
  • Call time.now() once and store result to avoid multiple calls affecting timing
  • Adjust assertions to verify time falls within the established window

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: miccy <9729864+miccy@users.noreply.github.com>
Copilot AI changed the title [WIP] Add documentation for migrating common-v8 to Bun and Biome Fix race condition in Time.test.ts timing assertions Feb 3, 2026
Copilot AI requested a review from miccy February 3, 2026 17:23
@miccy miccy marked this pull request as ready for review February 3, 2026 17:45
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Feb 3, 2026

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

  • 🔍 Trigger a full review

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

@miccy miccy merged commit 0b2cc23 into sync/bun-migration Feb 3, 2026
2 checks passed
@miccy miccy deleted the copilot/sub-pr-5-yet-again branch February 3, 2026 17:46
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