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
## Use ConfigureAwait(true) with FakeTimeProvider.Advance
45
+
## SynchronizationContext in xUnit Tests
46
46
47
-
The Advance method is used to simulate the passage of time. This can be useful in tests where you need to control the timing of asynchronous operations.
48
-
When awaiting a task in a test that uses `FakeTimeProvider`, it's important to use `ConfigureAwait(true)`.
47
+
### xUnit v2
49
48
50
-
Here's an example:
49
+
Some testing libraries such as xUnit v2 provide custom `SynchronizationContext` for running tests. xUnit v2, for instance, provides `AsyncTestSyncContext` that allows to properly manage asynchronous operations withing the test execution. However, it brings an issue when we test asynchronous code that uses `ConfigureAwait(false)` in combination with class like `FakeTimeProvider`. In such cases, the xUnit context may lose track of the continuation, causing the test to become unresponsive, whether the test itself is asynchronous or not.
This ensures that the continuation of the awaited task (i.e., the code that comes after the await statement) runs in the original context.
56
+
The `Advance` method is used to simulate the passage of time. Below is an example how to create a test for a code that uses `ConfigureAwait(false)` that ensures that the continuation of the awaited task (i.e., the code that comes after the await statement) works correctly.
57
57
58
58
For a more realistic example, consider the following test using Polly:
59
59
@@ -79,35 +79,21 @@ public class SomeService(TimeProvider timeProvider)
0 commit comments