Allow the runtime to time travel #83225
-
IdeaI'd like the runtime to provide a mechanism for the user to control the passage of time when using operations like Has the runtime team ever talked about something like this? Problem statementWhen testing code that depends on time the test results will hardly be deterministic. They will vary for instance due to hardware. A test suite might always run fine locally on a powerful developer machine but then be flaky when running on CI because the agents have much lower hardware specification. In my experience, even running tests in parallel can contribute to increased flakiness in this type of tests, probably due to pushing CPU more when compared to running the tests sequentially. Recently I faced an issue in one of my personal projects that I wished the runtime had better support for. The problem was some of my tests were flaky because they depended on time, more specifically in checking that X amount of actions happened in Y amount of time. The code being tested sometimes used a
The idea of the above is that in tests I can pass in a
Regardless of the details of what the above code sample is doing, what I'm trying to call out is that with RX and the Existing solutionsAbstract time dependencyAs a dotnet runtime user I can abstract away the parts of my code that interact with time related APIs. Then on tests I can pass in a a different implementation of my abstraction in order to test my app. Or perhaps I can avoid using the built in dotnet runtime APIs such as Patching the runtime during testsAs a dotnet runtime user I could use a library like Harmony to provide my own implementation of the dotnet runtime time APIs that I use on my app. This patching would only be applied on tests and the implementation I provide with the patching would have to provide a way to control time. This is something that the fake-async library does. As far as I understand the fundamental building block for this library is the replacement of dotnet APIs by using Harmony. For instance, see how fake-async replaces Task.Delay with something else. OtherThere probably are other variations of the above but is there anything else significantly different that would solve this problem ? Notes
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
#36617 (see the latest iterations on what's being proposed... it's not just current time). |
Beta Was this translation helpful? Give feedback.
-
Have you considered compiling your code to wasm and running it in the browser which you can throttle the performance |
Beta Was this translation helpful? Give feedback.
#36617 (see the latest iterations on what's being proposed... it's not just current time).