Skip to content

InternalExpectAsync does not await actionAsync() - causing actionAsync to run as a detached task #5537

@brah-mcdude

Description

@brah-mcdude

why does this pass:

/// <summary>
/// this test is a false positive
/// </summary>
/// <returns></returns>
[Fact]
public async Task ReplyingToProbeMessagesFunc()
{
    await EventFilter.Error().ExpectAsync(0, actionAsync: async () =>
    {
        var probe = CreateTestProbe();
        probe.Tell("hello");
        probe.ExpectMsg("hello");
        probe.Reply("world");
        await Task.Run(() => { ExpectMsg("world2"); });
        Assert.Equal(probe.Ref, LastSender);
    });
}

Looks to me like we forgot to.... you know, await the Task returned inside here:

/// <summary>
/// Async version of <see cref="InternalExpect"/>
/// </summary>
private async Task InternalExpectAsync(Func<Task> actionAsync, ActorSystem actorSystem, int expectedCount, TimeSpan? timeout = null)
{
await InterceptAsync<object>(() => { actionAsync(); return Task.FromResult<object>(null); }, actorSystem, timeout, expectedCount);
}

So I suspect the await Task.Run(() => { ExpectMsg("world2"); }); is running as a detatched task, which is incredibly annoying. We just need to update the TestKit to await those tasks internally and then this should pass.

Originally posted by @Aaronontheweb in #5529 (comment)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions