-
Notifications
You must be signed in to change notification settings - Fork 759
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FakeTimeProvider does not advance when GetTimestamp is called #5694
Comments
/cc: @dotnet/dotnet-extensions-fundamentals |
Thank you for raising this question. I did some checks and current implementation works as expected. There's one important reason why |
Personally I'd consider that an acceptable trade off, I'm not even sure I would call it a trade off... If I did this, would I normally expect the same value twice? var elapsedTime = provider.GetElapsedTime(startingTimestamp);
var elapsedTime2 = provider.GetElapsedTime(startingTimestamp); |
I see the point in your example. If we would implement it the same way as for public override long GetTimestamp()
{
DateTimeOffset result;
lock (Waiters)
{
result = _now;
_now += _autoAdvanceAmount;
}
WakeWaiters();
return result.Ticks;
} I was also concerned about introducing minor breaking change, but impact of this change would not have influence on users that use Another example to consider: [Fact]
public void GetElapsedTime_WithAutoadvance()
{
var timeProvider = new FakeTimeProvider()
{
AutoAdvanceAmount = TimeSpan.FromSeconds(1)
};
var st = timeProvider.GetTimestamp();
var elapsedTime = timeProvider.GetElapsedTime(st);
var elapsedTime2 = timeProvider.GetElapsedTime(st);
Assert.Equal(TimeSpan.FromSeconds(1), elapsedTime);
Assert.Equal(TimeSpan.FromSeconds(2), elapsedTime2);
} I initially thought it would result in That being said this proposition would make sense. I'm reopening this to hear feedback also from other people. |
Description
This is how I expect it to work, not sure if it's a bug, intentional or an oversight.
Reproduction Steps
As above ^^
Expected behavior
I would expect that when checking the elapsed time that it should match what is specified in AutoAdvanceAmount.
Actual behavior
The elapsed time is zero.
Regression?
No idea.
Known Workarounds
Currently I can work around the issue by advancing the timer myself in between the calls to GetTimestamp and GetElapsedTime.
Configuration
.NET 8
Other information
extensions/src/Libraries/Microsoft.Extensions.TimeProvider.Testing/FakeTimeProvider.cs
Line 165 in cfed375
This shows that it just returns the number of ticks from now.
Maybe it needs to do something similar to
extensions/src/Libraries/Microsoft.Extensions.TimeProvider.Testing/FakeTimeProvider.cs
Line 83 in cfed375
The text was updated successfully, but these errors were encountered: