-
Notifications
You must be signed in to change notification settings - Fork 1k
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
InternalExpectAsync does not await actionAsync() - causing actionAsync to run as a detached task #5537
Comments
Just need to |
For the record - this is the exception thrown by - ExpectMsg("world2"): Akka.TestKit.Xunit2.Internals.AkkaEqualException
HResult=0x80131500
Message=Assert.Equal() Failure
Expected: world2
Actual: world
Source=Akka.TestKit.Xunit2
StackTrace:
at Akka.TestKit.Xunit2.XunitAssertions.AssertEqual[T](T expected, T actual, String format, Object[] args) in C:\Users\brahm\source\repos\akka.net\src\contrib\testkits\Akka.TestKit.Xunit2\XunitAssertions.cs:line 68
at Akka.TestKit.TestKitBase.<>c__DisplayClass108_0`1.<ExpectMsg>b__0(T m) in C:\Users\brahm\source\repos\akka.net\src\core\Akka.TestKit\TestKitBase_Expect.cs:line 54
at Akka.TestKit.TestKitBase.<>c__DisplayClass119_0`1.<InternalExpectMsgEnvelope>b__2(T m, IActorRef sender) in C:\Users\brahm\source\repos\akka.net\src\core\Akka.TestKit\TestKitBase_Expect.cs:line 222
at Akka.TestKit.TestKitBase.InternalExpectMsgEnvelope[T](Nullable`1 timeout, Action`2 assert, String hint, Boolean shouldLog) in C:\Users\brahm\source\repos\akka.net\src\core\Akka.TestKit\TestKitBase_Expect.cs:line 252
at Akka.TestKit.TestKitBase.InternalExpectMsgEnvelope[T](Nullable`1 timeout, Action`1 msgAssert, Action`1 senderAssert, String hint) in C:\Users\brahm\source\repos\akka.net\src\core\Akka.TestKit\TestKitBase_Expect.cs:line 224
at Akka.TestKit.TestKitBase.InternalExpectMsg[T](Nullable`1 timeout, Action`1 msgAssert, String hint) in C:\Users\brahm\source\repos\akka.net\src\core\Akka.TestKit\TestKitBase_Expect.cs:line 199
at Akka.TestKit.TestKitBase.ExpectMsg[T](T message, Nullable`1 timeout, String hint) in C:\Users\brahm\source\repos\akka.net\src\core\Akka.TestKit\TestKitBase_Expect.cs:line 54
at Akka.TestKit.Tests.Xunit2.TestEventListenerTests.AllTestForEventFilterBase`1.<ExpectAsync_should_await_actionAsync>b__22_1() in C:\Users\brahm\source\repos\akka.net\src\core\Akka.TestKit.Tests\TestEventListenerTests\AllTestForEventFilterBase.cs:line 183
at System.Threading.Tasks.Task.InnerInvoke()
at System.Threading.Tasks.Task.<>c.<.cctor>b__272_0(Object obj)
at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state) |
@Aaronontheweb: return Task.FromResult<object>(null); Maybe you can? |
…tionAsync to run as a detached task #5537 (#5538) Co-authored-by: Aaron Stannard <[email protected]>
resolved via #5538 |
Issue seems to appear in another scenario: This 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: |
) * simplified test. i checked that it properly reproduces the issue. * I added "actionAsync:" parameter name in order to reproduce issue #5537 Co-authored-by: Gregorius Soedharmo <[email protected]>
why does this pass:
Looks to me like we forgot to.... you know,
await
theTask
returned inside here:akka.net/src/core/Akka.TestKit/EventFilter/Internal/EventFilterApplier.cs
Lines 454 to 460 in 38b7443
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)
The text was updated successfully, but these errors were encountered: