Skip to content

Commit

Permalink
Fix TimeProvider Test (#111080)
Browse files Browse the repository at this point in the history
  • Loading branch information
tarekgh authored Jan 6, 2025
1 parent 1a97d63 commit 62d128a
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/libraries/Common/tests/System/TimeProviderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down

0 comments on commit 62d128a

Please sign in to comment.