Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CompleteWithinAsync with AssertionScope will wait task to return value #2004

Closed
xzxzxc opened this issue Sep 20, 2022 · 3 comments
Closed

CompleteWithinAsync with AssertionScope will wait task to return value #2004

xzxzxc opened this issue Sep 20, 2022 · 3 comments
Assignees

Comments

@xzxzxc
Copy link

xzxzxc commented Sep 20, 2022

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>).
@lg2de
Copy link
Contributor

lg2de commented Sep 21, 2022

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

@lg2de
Copy link
Contributor

lg2de commented Nov 17, 2022

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.

@xzxzxc
Copy link
Author

xzxzxc commented Nov 17, 2022

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

@xzxzxc xzxzxc closed this as completed Nov 17, 2022
dennisdoomen pushed a commit that referenced this issue Nov 19, 2022
…ssertion scope (#2033)

* Add new unit test to verify #2004

* fix test name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants