From b9a1ae787a2094142ef5fbd0aea5e24136c4a695 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 13 Jul 2026 08:24:16 +0000 Subject: [PATCH 1/2] Initial plan From 3cb0343a77782d4bb1c6fbbddbc7a35cc5b9e2a3 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 13 Jul 2026 08:59:36 +0000 Subject: [PATCH 2/2] Make browser StopwatchTests robust to coarse clock resolution Co-authored-by: pavelsavara <271576+pavelsavara@users.noreply.github.com> --- .../System/Diagnostics/Stopwatch.cs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/libraries/System.Runtime/tests/System.Runtime.Extensions.Tests/System/Diagnostics/Stopwatch.cs b/src/libraries/System.Runtime/tests/System.Runtime.Extensions.Tests/System/Diagnostics/Stopwatch.cs index 64305d4deb6833..0dfb578e20cc20 100644 --- a/src/libraries/System.Runtime/tests/System.Runtime.Extensions.Tests/System/Diagnostics/Stopwatch.cs +++ b/src/libraries/System.Runtime/tests/System.Runtime.Extensions.Tests/System/Diagnostics/Stopwatch.cs @@ -163,6 +163,24 @@ public static void ElapsedMilliseconds_WithinExpectedWindow() private static void Sleep(int milliseconds) { + if (PlatformDetection.IsBrowser) + { + // The browser's monotonic clock (performance.now) has a coarse, security-clamped + // resolution and blocking waits don't advance real time on the single browser thread, + // so a fixed-timeout WaitOne isn't guaranteed to move the Stopwatch past its resolution + // boundary. Spin until at least one TimeSpan tick of elapsed time is observable so that + // callers relying on a measurable delta (e.g. Elapsed > TimeSpan.Zero) behave reliably. + long start = Stopwatch.GetTimestamp(); + long minTicks = Math.Max(1, Stopwatch.Frequency / TimeSpan.TicksPerSecond); + do + { + s_sleepEvent.WaitOne(milliseconds); + } + while (Stopwatch.GetTimestamp() - start < minTicks); + + return; + } + s_sleepEvent.WaitOne(milliseconds); } }