Repository navigation
[Tests] Fix random failure of Debounce_Default - #5478
Closed
NoobMaster (oONoobMasterOo) wants to merge 1 commit into
Closed
NoobMaster (oONoobMasterOo) wants to merge 1 commit into
NoobMaster (oONoobMasterOo) wants to merge 1 commit into
Conversation
Task.Delay relies on the system timer, which can complete a few milliseconds before a Stopwatch measures the full delay (46 ms measured for a 50 ms delay on Windows), so the test failed randomly.
NoobMaster (oONoobMasterOo)
requested review from
Denis Voituron (dvoituron) and
Vincent Baaij (vnbaaij)
as code owners
October 19, 2026 09:16
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The focused test-only adjustment addresses timing variance while retaining a meaningful minimum-delay check.
No open issues 🎉
What changed in this PR
Reduces intermittent failures in Debounce_Default caused by system-timer resolution.
Changes:
- Adds a 16 ms tolerance, lowering the minimum elapsed-time assertion to 34 ms.
- Preserves completion and action-execution checks.
| File | Description |
|---|---|
| tests/Core/Utilities/DebounceTests.cs | Allows timer-resolution variance in the debounce timing assertion. |
Review effort: Balanced
Collaborator
|
Thanks for investigating this. I don’t agree with lowering the threshold from 50 ms to 34 ms to address the flaky test. It weakens the assertion on every platform, including Linux, and could hide a regression in the requested delay. I’d prefer a deterministic test using a TimeProvider and simulated time, rather than introducing a fixed tolerance based on Windows timer granularity. |
6 of 10 tasks
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.
DebounceTests.Debounce_Defaultfails randomly: it asserts that at least 50 ms elapsed afterRunAsync(50, ...), measured with aStopwatch.Debouncewaits withTask.Delay, which relies on the system timer (about 15.6 ms resolution on Windows), so it can complete a few milliseconds before theStopwatchmeasures 50 ms.Measured locally (Windows, 40 runs): the shortest delay was 46.11 ms, and the test failed 1 time out of 20 runs.
The assertion now allows one timer tick (
50 - timerResolution, withtimerResolution = 16). It still verifies that the action is debounced and not executed immediately.Unit Tests
Updated
Debounce_Default.