Repository navigation
Fix flaky timing assertions in telemetry tests - #13
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
CI on main failed with a flaky timing assertion in
src/__tests__/telemetry-deduplication.test.ts:254:apiResponseTime >= 1514The 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:
>= 20msto>= 15ms(5ms tolerance)>= 15msto>= 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()andDate.now()without compromising the test's validity - we still verify that response times are reasonable and non-zero.