CompleteWithinAsync with AssertionScope will wait task to return value
Description
In the case of using AssertionScope with the CompleteWithinAsync method over the delegate that returns a task with a result (Task<T>), the method will wait until the task is completed.
Complete minimal example reproducing the issue
using var _ = new AssertionScope();
var someAsyncWork = async () =>
{
while (true)
await Task.Delay(20.Milliseconds());
return 1;
};
await someAsyncWork.Should().CompleteWithinAsync(500.Milliseconds());
Expected behavior:
The CompleteWithinAsync method will throw an exception in a decent period of time.
Actual behavior:
Execution stucks in the infinite loop.
Versions
I'm using FluentAssertions 6.7.0 with net6.0.
Additional Information
Issue disappears with one of the following changes:
- remove usage of the
AssertionScope; - remove
returnstatement from thesomeAsyncWork(change the type of the delegate fromFunc<Task<T>>toFunc<Task>).
@dennisdoomen, I'll take care. Please assign this issue to me.
Hey @xzxzxc , sorry for strong delay! Today I finally tried to reproduce. I guess, it was already fixed while refactoring in #1967. Please check again with version 6.8.0. At least I cannot reproduce anymore.
@lg2de thank you! I can confirm, the issue is fixed in the 6.8.0.