Problem
The test needsCatchUp edge cases > handles exactly at threshold is flaky and failed in CI.
Root Cause
The test calculates exactlyAtThreshold using Date.now(), then needsCatchUp() internally calls Date.now() again. If even 1ms passes between those calls, the elapsed time exceeds the threshold and the test fails.
const exactlyAtThreshold = new Date(Date.now() - DEFAULT_CATCHUP_THRESHOLD_MS).toISOString();
// ... time passes ...
expect(needsCatchUp(state)).toBe(false); // needsCatchUp calls Date.now() again
Fix
Inject a clock/time provider into needsCatchUp() so tests can control time deterministically.
Acceptance Criteria
References
Problem
The test
needsCatchUp edge cases > handles exactly at thresholdis flaky and failed in CI.Root Cause
The test calculates
exactlyAtThresholdusingDate.now(), thenneedsCatchUp()internally callsDate.now()again. If even 1ms passes between those calls, the elapsed time exceeds the threshold and the test fails.Fix
Inject a clock/time provider into
needsCatchUp()so tests can control time deterministically.Acceptance Criteria
needsCatchUp()accepts optionalnowparameter or clock injectionReferences