We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 50853c1 commit 6d6062fCopy full SHA for 6d6062f
tests/bunit.testassets/AssertExtensions/TaskAssertionExtensions.cs
@@ -4,7 +4,15 @@ public static class TaskAssertionExtensions
4
{
5
public static async Task ShouldCompleteWithin(this Task task, TimeSpan timeout)
6
7
- if (task != await Task.WhenAny(task, Task.Delay(timeout)))
8
- throw new TimeoutException();
+#if NET6_0_OR_GREATER
+ await task.WaitAsync(timeout);
9
+#else
10
+ var cts = new CancellationTokenSource();
11
+ var delayTask = Task.Delay(timeout, cts.Token);
12
+ if (task != await Task.WhenAny(task, delayTask))
13
+ throw new TimeoutException();
14
+
15
+ cts.Cancel();
16
+#endif
17
}
18
0 commit comments