Skip to content

InterceptAsync seems to run func() as a detached task #5586

@brah-mcdude

Description

@brah-mcdude

This issue seems to be very similar to this issue:
InternalExpectAsync does not await actionAsync() - causing actionAsync to run as a detached task #5537

Repro:
This is my code:

        protected async Task ExpectLogNoWarningsNorErrorsAsync(Func<Task> action)
        {
            await CreateEventFilter(Sys)
                .Custom(CustomErrorOrWarningFilter)
                .ExpectAsync(0, TimeSpan.FromSeconds(3),
                async () =>
                {
                    await action();
                });
        }

Invokes this code:

        /// <summary>
        /// Async version of <see cref="Intercept{T}"/>
        /// </summary>
        protected Task<T> InterceptAsync<T>(Func<T> func, ActorSystem system, TimeSpan? timeout, int? expectedOccurrences, MatchedEventHandler matchedEventHandler = null)
        {
            return InterceptAsync(() => Task.FromResult(func()), system, timeout, expectedOccurrences, matchedEventHandler);
        }

Which seems to invoke:
func()
without awaiting it, hence causing func() to run as a detached task.

Originally posted by @brah-mcdude in #5537 (comment)

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions