Skip to content

Async lambdas passed to Assert.That(...) are evaluated too early #3137

@m-gasser

Description

@m-gasser

Lambdas passed to Assert.That(...) are intended to be evaluated during AssertionBuilder.GetAssertionData(). However async lambdas are already started when AsAssertionData() is called, which happens already during builder execution.
The underlying reason is, that when a Func is invoked to get the Task, the Task may immediately be scheduled on the thread pool.

It might be possible to wrap a Func into a ValueTask in a way that guarantees lazy evaluation, which would fix the bug. However making the laziness requirement more explicit is probably better. This way it is not only less error-prone but it should also make the code more clear.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions