fluentassertions icon indicating copy to clipboard operation
fluentassertions copied to clipboard

CompleteWithinAsync with AssertionScope will wait task to return value

Open xzxzxc opened this issue 3 years ago • 1 comments

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 return statement from the someAsyncWork (change the type of the delegate from Func<Task<T>> to Func<Task>).

xzxzxc avatar Sep 20 '22 23:09 xzxzxc

@dennisdoomen, I'll take care. Please assign this issue to me.

lg2de avatar Sep 21 '22 08:09 lg2de

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 avatar Nov 17 '22 16:11 lg2de

@lg2de thank you! I can confirm, the issue is fixed in the 6.8.0.

xzxzxc avatar Nov 17 '22 20:11 xzxzxc