From 62d128a4c361866a1432959bbf2207fa67962bc6 Mon Sep 17 00:00:00 2001 From: Tarek Mahmoud Sayed <10833894+tarekgh@users.noreply.github.com> Date: Mon, 6 Jan 2025 07:03:05 -0800 Subject: [PATCH] Fix TimeProvider Test (#111080) --- src/libraries/Common/tests/System/TimeProviderTests.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/libraries/Common/tests/System/TimeProviderTests.cs b/src/libraries/Common/tests/System/TimeProviderTests.cs index 119a35610f1f5..e0840f09d1cdb 100644 --- a/src/libraries/Common/tests/System/TimeProviderTests.cs +++ b/src/libraries/Common/tests/System/TimeProviderTests.cs @@ -143,7 +143,9 @@ public void TestProviderTimer(TimeProvider provider, int minMilliseconds) state.TokenSource.Token.WaitHandle.WaitOne(Timeout.InfiniteTimeSpan); state.TokenSource.Dispose(); - Assert.Equal(4, state.Counter); + // In normal conditions, the timer callback should be called 4 times. Sometimes the timer callback could be queued and fired after the timer was disposed. + Assert.True(state.Counter >= 4, $"The timer callback was expected to be called at least 4 times, but was called {state.Counter} times"); + Assert.Equal(400, state.Period); Assert.True(minMilliseconds <= state.Stopwatch.ElapsedMilliseconds, $"The total fired periods {state.Stopwatch.ElapsedMilliseconds}ms expected to be greater then the expected min {minMilliseconds}ms"); }