orleans
orleans copied to clipboard
Tests relied on `FakeTimeProvider` failed after upgrading to orleans 8.2.0
In some of our grains we relied on TimeProvider and have written some time-based tests using Microsoft.Orleans.TestingHost but after upgrading to Orleans 8.2.0 it seems there are some unpredictable problems for those test which relied on FakeTimeProvider
we are using this code siloBuilder.Services.AddSingleton<TimeProvider>(FakeTime); to setup a fake time-provider.
and now we are facing some unpredictable problems like:
- Implicit subscription not work if we use
siloBuilder.Services.AddSingleton<TimeProvider>(FakeTime). - In some cases
FakeTime.SetUtcNow(someTime)took 10min to execute
Orleans doesn't yet fully support testing with a fake TimeProvider. There are some places in the runtime where we have added support for TimeProvider, but it's not everywhere yet.
Yes and that's exactly the problem, as you changed some part of runtime using TimeProvider when we replace TimeProvider with a fake one to test our Grains Behaviors the Orleans-Runtime also take affect and work in an unpredictable behavior.
Isn't it a better practice to use Keyed-Service for TimeProvider in Orleans-Runtime to avoid conflict?
@zeinali-ali perhaps Keyed DI would be useful in the interim before all timers are replaced. For now, are you able to use keyed DI to inject your fake time provider into your grains? Apologies for the hassle
Sure, we can switch to Keyed-DI to avoid conflict.
However we currently rolled-back to 8.1.0.
I'm just suggesting that a Keyed-DI TimeProvider used in libraries and frameworks can be a better choice to avoid such a conflicts with other libraries and user codes
I am now in the process of upgrading our application to .NET 9 which binds me to this partial implementation in Orleans. Is there a timeline for when Orleans will implement (keyed) TimeProvider instances consistently throughout the framework?
Thanks for your work on this!
@KSlingerland are you able to use Keyed DI for TimeProvider at the application level?
I was able to substitute with Keyed DI, it did complicate things a bunch with testing but it's a workaround for now. Thanks for the quick response!