Make browser StopwatchTests robust to coarse clock resolution#130605
Merged
Conversation
Co-authored-by: pavelsavara <271576+pavelsavara@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix System.Diagnostics.Tests.StopwatchTests.GetTimestamp test in CI
Make browser StopwatchTests robust to coarse clock resolution
Jul 13, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adjusts System.Diagnostics.Tests.StopwatchTests to reduce intermittent failures on browser/WASM by making the test’s sleep helper wait until Stopwatch.GetTimestamp() observably advances, rather than assuming a single fixed wait crosses the clock’s resolution boundary.
Changes:
- Add a browser-specific loop in the
Sleep(int milliseconds)helper to retry waiting until the stopwatch timestamp advances.
Member
|
/ba-g CI failure is #130618 |
akoeplinger
approved these changes
Jul 13, 2026
eiriktsarpalis
pushed a commit
that referenced
this pull request
Jul 15, 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.
Fixes #62021
StopwatchTests.GetTimestampandStartNewAndResetfail intermittently on the browser/WASM target: consecutiveGetTimestamp()reads return equal values andElapsedmeasures zero.Root cause
On browser,
Stopwatch.GetTimestamp()→minipal_hires_ticks()→ emscriptenclock_gettime(CLOCK_MONOTONIC), backed byperformance.now(), which is security-clamped to a coarse resolution. Blocking waits (ManualResetEvent.WaitOne(timeout)) also don't advance real time on the single browser thread. A fixed-timeout sleep therefore isn't guaranteed to move the timestamp past a resolution boundary. The monotonic hi-res clock in use is already the best clock the browser exposes — there is no higher-resolution alternative to switch to — so the test must tolerate coarse resolution rather than assume a fixed sleep crosses a boundary.Changes
Stopwatch.cstestSleephelper: on browser only, spin (re-issuing the existingWaitOne) until the Stopwatch timestamp advances by at least oneTimeSpantick. Non-browser platforms are unchanged.This guarantees a measurable delta before dependent asserts (
Assert.NotEqual(ts1, ts2),Elapsed > TimeSpan.Zero), coveringGetTimestamp,StartNewAndReset,ConstructStartAndStop, andOverridesToString. No tests are disabled.Note
This PR was generated with the assistance of GitHub Copilot.