Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
brah-mcdude opened this issue Feb 7, 2022 · 0 comments
Closed

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

brah-mcdude opened this issue Feb 7, 2022 · 0 comments
Assignees
Labels
akka-testkit Akka.NET Testkit issues
Milestone

Comments

@brah-mcdude
Copy link
Contributor

brah-mcdude commented Feb 7, 2022

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)

@Aaronontheweb Aaronontheweb added the akka-testkit Akka.NET Testkit issues label Feb 10, 2022
@Aaronontheweb Aaronontheweb added this to the 1.4.33 milestone Feb 10, 2022
Aaronontheweb pushed a commit that referenced this issue Feb 10, 2022
* repro issue: InterceptAsync seems to run func() as a detached task #5586

* resolved issue: InterceptAsync seems to run func() as a detached task #5586

* added notes: "func might not get awaited"

* Fix API breaking changes

* Remove null default value

Co-authored-by: Gregorius Soedharmo <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
akka-testkit Akka.NET Testkit issues
Projects
None yet
Development

No branches or pull requests

3 participants