Skip to content

CompleteWithinAsync does not consider execution time of sync code  #1761

@xzxzxc

Description

@xzxzxc

Description

I have two equivalent tests of function that returns Task. First one uses CompleteWithinAsync() method, second one ExecutionTime(). Inside function before async part there is some sync code, but for simplicity of example I changed it to Thread.Sleep().

[Fact]
public async Task Test1()
{
    var func = async () => Thread.Sleep(10);
    await func.Should().CompleteWithinAsync(1.Milliseconds());
}

[Fact]
public void Test2()
{
    var func = async () => Thread.Sleep(10);
    func.ExecutionTime().Should().BeLessThan(1.Milliseconds());
}

Expected behavior:

Two tests fail.

Actual behavior:

First test does not fail.

Versions

I'm using Fluent Assertions version 6.2.0 with net6.0 and c# 9.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions