Repository navigation
[Debounce] Use a TimeProvider for testing - #5480
Merged
Denis Voituron (dvoituron) merged 3 commits intoOct 21, 2026
Merged
Denis Voituron (dvoituron) merged 3 commits into
Denis Voituron (dvoituron) merged 3 commits into
Conversation
Debounce_Default measured the delay with a Stopwatch, which randomly failed on Windows because Task.Delay can complete a few milliseconds early. Debounce now waits on a TimeProvider (TimeProvider.System by default), and the test advances a FakeTimeProvider.
NoobMaster (oONoobMasterOo)
requested review from
Denis Voituron (dvoituron) and
Vincent Baaij (vnbaaij)
as code owners
October 19, 2026 11:33
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The focused changes have no identified blocking issues; tests were not executed in this review environment.
No open issues 🎉
What changed in this PR
Replaces wall-clock timing in the debounce delay test with simulated time, addressing the intermittent failure discussed in #5478.
Changes:
- Adds an internal
TimeProviderconstructor while retainingTimeProvider.Systempublicly. - Checks the 50 ms delay using
FakeTimeProvider. - Adds the required test dependency.
| File | Description |
|---|---|
| tests/Core/Utilities/DebounceTests.cs | Replaces stopwatch timing with simulated-time assertions. |
| tests/Core/Components.Tests.csproj | References the time-provider testing package. |
| src/Core/Utilities/Debounce.cs | Supports an injected time provider for delays. |
| Directory.Packages.props | Defines the testing package version. |
Review effort: Balanced
Collaborator
|
We've added a new requirement regarding PRs
|
Contributor
Author
Checked |
Denis Voituron (dvoituron)
approved these changes
Oct 21, 2026
This was referenced Nov 16, 2026
Merged
Closed
This was referenced Nov 23, 2026
Closed
This was referenced Nov 30, 2026
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.
Pull Request
📖 Description
DebounceTests.Debounce_Defaultfailed randomly: it measured the delay with aStopwatch, andTask.Delaycan complete a few milliseconds before 50 ms on Windows (system timer resolution).Changes
Debouncewaits withTask.Delay(TimeSpan, TimeProvider, CancellationToken).TimeProvider.System, so the behavior is unchanged. An internal constructor accepts aTimeProviderfor the tests.Microsoft.Extensions.TimeProvider.Testing(FakeTimeProvider).🎫 Issues
👩💻 Reviewer Notes
Test-only purpose; the public
Debounceconstructor still usesTimeProvider.System.📑 Test Plan
Unit tests
Updated
Debounce_Default: afterRunAsync(50, ...), advancing the time by 49 ms doesn't run the action, and advancing 1 more ms runs it. No real waiting, and the exact 50 ms delay is checked: with a delay shortened by 10 ms, the test fails.tests/Coresuite on this branch: 4903 tests, 0 failed (ata170367fb).Other checks
DebounceTests: 9 / 9 pass.net8.0(Task.Delay(TimeSpan, TimeProvider, CancellationToken)is available since .NET 8).✅ Checklist
General
AI contribution declaration
AI assistance is allowed; fully AI-generated or autonomous pull requests without meaningful human review are not accepted. See the AI contribution policy.
Component-specific
⏭ Next Steps
None.