From 5fc9847c1f46f834c0c0d0bf994ac05a74fc6029 Mon Sep 17 00:00:00 2001 From: Erik Darling <2136037+erikdarlingdata@users.noreply.github.com> Date: Sat, 24 Oct 2026 05:53:37 -0400 Subject: [PATCH] Test helper: Elapse holds at least the time it is given --- Darling/Darling.Tests/TestTimeHelpers.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Darling/Darling.Tests/TestTimeHelpers.cs b/Darling/Darling.Tests/TestTimeHelpers.cs index 807afac4bb..5228dc2c06 100644 --- a/Darling/Darling.Tests/TestTimeHelpers.cs +++ b/Darling/Darling.Tests/TestTimeHelpers.cs @@ -62,7 +62,16 @@ internal static bool TryWaitUntil(Func condition, TimeSpan timeout, TimeSp /// Holds the calling thread for because the elapsed time is the test's input (a /// fake slow call, a lock held open), not because anything is being waited for. /// - internal static void Elapse(TimeSpan duration) => Pause(duration); + internal static void Elapse(TimeSpan duration) + { + /* A timed wait on Windows can return up to one timer tick early, so a single Pause can hold for less than it was + asked to (#6704's CI: 60 ms asked, 47 ms measured by Stopwatch). Pause again for whatever is left. */ + var started = TimeProvider.System.GetTimestamp(); + for (var left = duration; left > TimeSpan.Zero; left = duration - TimeProvider.System.GetElapsedTime(started)) + { + Pause(left); + } + } /// The polling loop, with the pause and the clock passed in so the unit tests need no real time. internal static bool WaitCore(Func condition, TimeSpan timeout, TimeSpan poll, Action pause, Func elapsed)