Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public async Task VerifyAsync_WhenMultipleIterationsAreNecessary_ShouldStopWhenS
using CancellationTokenSource cts = new();
CancellationToken token = cts.Token;

_ = Task.Run(async () =>
Task backgroundTask = Task.Run(async () =>
{
for (int i = 0; i < 1000; i++)
{
Expand All @@ -65,6 +65,8 @@ public async Task VerifyAsync_WhenMultipleIterationsAreNecessary_ShouldStopWhenS
}, token);

await That(((IAsyncVerificationResult)result).VerifyAsync(l => l.Length > 20)).IsTrue();
cts.Cancel();
await backgroundTask;
}

[Fact]
Expand Down Expand Up @@ -142,11 +144,11 @@ public async Task Within_ShouldAbortAsSoonAsConditionIsSatisfied()
using CancellationTokenSource cts = new();
CancellationToken token = cts.Token;

_ = Task.Run(async () =>
Task backgroundTask = Task.Run(async () =>
{
for (int i = 0; i < 100; i++)
{
await Task.Delay(100, CancellationToken.None);
await Task.Delay(100, CancellationToken.None).ConfigureAwait(false);
sut.Dispense("Dark", i);
if (token.IsCancellationRequested)
{
Expand All @@ -160,6 +162,7 @@ public async Task Within_ShouldAbortAsSoonAsConditionIsSatisfied()
.AtLeastOnce();
sw.Stop();
cts.Cancel();
await backgroundTask;

await That(sw.Elapsed).IsLessThan(TimeSpan.FromSeconds(2));
}
Expand Down