You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am working with a non-periodic Timer that re-schedules itself with the ITimer.Change method. I noticed that FakeTimeProvider.Advance only ever executes the timer once, even if I provide a TimeSpan that covers multiple executions.
Reproduction Steps
publicclassTimerBugRepro{[Fact]publicvoidTestWithSystemTime()// Works{Assert.Equal(2,RunTestWithTimeProvider(TimeProvider.System,()=>Thread.Sleep(TimeSpan.FromSeconds(3))));}[Fact]publicvoidTestWithFakeTime()// Fails{varfakeTime=newFakeTimeProvider();Assert.Equal(2,RunTestWithTimeProvider(fakeTime,()=>fakeTime.Advance(TimeSpan.FromSeconds(3))));}privateintRunTestWithTimeProvider(TimeProvidertimeProvider,ActionsleepAction){intcount=0;ITimertimer=null;timer=timeProvider.CreateTimer(
_ =>{Interlocked.Increment(refcount);timer.Change(TimeSpan.FromSeconds(2),Timeout.InfiniteTimeSpan);},null,Timeout.InfiniteTimeSpan,Timeout.InfiniteTimeSpan);timer.Change(TimeSpan.FromMilliseconds(1),Timeout.InfiniteTimeSpan);// Both tests work for TimeSpan.ZerosleepAction();returncount;}}
Expected behavior
The FakeTimeProvider.Advance should correctly simulate the behavior for TimeProvider.System + Thread.Sleep.
Actual behavior
The Fake-Timer does not get re-sheduled correctly.
Description
I am working with a non-periodic Timer that re-schedules itself with the
ITimer.Change
method. I noticed thatFakeTimeProvider.Advance
only ever executes the timer once, even if I provide aTimeSpan
that covers multiple executions.Reproduction Steps
Expected behavior
The
FakeTimeProvider.Advance
should correctly simulate the behavior forTimeProvider.System
+Thread.Sleep
.Actual behavior
The Fake-Timer does not get re-sheduled correctly.
Regression?
No response
Known Workarounds
No response
Configuration
.NET SDK version: 9.0.100
TargetFramework: net8.0
Microsoft.Extensions.TimeProvider.Testing version: 9.0.0
OS: Windows 10 10.0.19045
Other information
No response
The text was updated successfully, but these errors were encountered: