Skip to content

Fix flaky timing assertions in telemetry tests - #13

Merged
JamesSmartCell merged 1 commit into
masterfrom
cursor/fix-flaky-timing-tests-1b9a
Nov 17, 2026
Merged

JamesSmartCell merged 1 commit into
masterfrom
cursor/fix-flaky-timing-tests-1b9a

Conversation

@JamesSmartCell

Copy link
Copy Markdown
Owner

Problem

CI on main failed with a flaky timing assertion in src/__tests__/telemetry-deduplication.test.ts:254:

  • Expected: apiResponseTime >= 15
  • Actual: 14

The timer fired ~1ms early on the Pi runner due to JavaScript timer precision limitations.

Solution

Relaxed the timing assertions to account for inherent timer imprecision:

  • First test: Changed from >= 20ms to >= 15ms (5ms tolerance)
  • Second test: Changed from >= 15ms to >= 10ms (5ms tolerance)

This is the recommended approach when fake timers aren't practical for integration tests that involve real HTTP requests and async I/O.

Testing

✅ All 244 tests pass across 14 test files
✅ Both timing tests now pass reliably
✅ No production behavior changed

Notes

The tolerance accounts for the known imprecision of setTimeout() and Date.now() without compromising the test's validity - we still verify that response times are reasonable and non-zero.

Open in Web Open in Cursor 

The telemetry-deduplication test suite had flaky timing assertions that
could fail when timers fire slightly early (~1ms) due to system load or
JavaScript timer precision limitations. This was particularly noticeable
on Pi runners where the test expected >= 15ms but got 14ms.

Changes:
- Relaxed first test assertion from >= 20ms to >= 15ms (5ms tolerance)
- Relaxed second test assertion from >= 15ms to >= 10ms (5ms tolerance)

The tolerance accounts for the inherent imprecision of setTimeout and
Date.now() without changing production behavior. All 244 tests pass.

Co-authored-by: James Brown <JamesSmartCell@users.noreply.github.com>
@JamesSmartCell
JamesSmartCell merged commit 16b26fb into master Nov 17, 2026
4 checks passed
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