Skip to content

test(api): pin the clock in the notification silence route test - #1650

Merged
scttbnsn merged 1 commit into
dev/v1.9from
fix/v1.9-silence-test-clock
Nov 19, 2026
Merged

scttbnsn merged 1 commit into
dev/v1.9from
fix/v1.9-silence-test-clock

Conversation

@scttbnsn

@scttbnsn scttbnsn commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Makes the notification silence route test deterministic. It compared a computed expiry against Date.now() taken a moment later, so on a loaded machine it saw 1799999 instead of 1800000 and failed an unrelated push gate. The test now pins the clock.

✨ Added

  • vi.useFakeTimers() in beforeEach of app/api/notification-silence.test.ts.
  • vi.setSystemTime(new Date('2026-03-01T12:00:00Z')) in beforeEach. Fixes the clock for each test.
  • vi.useRealTimers() in afterEach. Restores real timers after each test.

🔧 Changed

  • Notification silence route tests now run with a pinned clock. This removes timing dependence in expiry checks that compared a computed value with a later Date.now() call.

🐛 Fixed

  • Flaky expiry assertion. On a loaded machine, a later Date.now() could return a value 1 ms ahead, producing 1799999 instead of 1800000. Pinned time prevents this.

Diff: 1 file, +3/-0 in app/api/notification-silence.test.ts.

Concerns:

  • Verify that vi.useRealTimers() runs even when a test throws. It runs in afterEach, so it does.
  • Verify no other test in this file depends on real elapsed time (e.g., setTimeout waits). Fake timers stop them unless advanced.
  • Verify silenceStore.resetSilencesForTests() and resetSuppressionForTests() do not await real timers.
  • Check for the same non-deterministic Date.now() pattern in sibling notification test files.

@coderabbitai

coderabbitai Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The notification-silence tests now enable fake timers and set the system time to 2026-03-01T12:00:00Z for each test. Teardown restores real timers.

Change: Other

Merge Risk: Minimal · up to b851f

This is a test-only change that makes the notification silence test deterministic. It has no production behavior impact, and no merge-blocking risk remains.

Pre-merge checks: Passed 2

Check name Status Explanation
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • 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

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between e384795 and b851f59.

Files selected for processing: 1

  • app/api/notification-silence.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.

@codecov

codecov Bot commented Nov 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@scttbnsn
scttbnsn merged commit 45dab74 into dev/v1.9 Nov 19, 2026
33 checks passed
@scttbnsn
scttbnsn deleted the fix/v1.9-silence-test-clock branch November 19, 2026 20:10
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.

1 participant