Skip to content

Async support for hooks is broken because of incorrect code in HookMetadataGenerator #2935

@DavidZidar

Description

@DavidZidar

Hi,

I updated to the latest TUnit version 0.56.5 and now my async [Before(Test)] hooks aren't working properly because they are not being awaited.

I have traced the error to the following line:

writer.AppendLine("await AsyncConvert.ConvertObject(() => result);");

It seems to be trying to convert result to something that can be awaited but since it is passing in a local Func<object> then it will always end up running syncFunc() in AsyncConvert which isn't the intention.

if (invoke is Func<object> syncFunc)
{
syncFunc();
return;
}

To be clear, the before hook is being called, but TUnit continues execution without waiting for the async operation to complete so tests end up running before the hook is done running.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions