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

Akka.TestKit: Watch and Unwatch are secretly asynchronous #7064

Closed
Aaronontheweb opened this issue Jan 17, 2024 · 0 comments · Fixed by #7037
Closed

Akka.TestKit: Watch and Unwatch are secretly asynchronous #7064

Aaronontheweb opened this issue Jan 17, 2024 · 0 comments · Fixed by #7037
Labels
akka-testkit Akka.NET Testkit issues confirmed bug
Milestone

Comments

@Aaronontheweb
Copy link
Member

Aaronontheweb commented Jan 17, 2024

Nasty, decade old bug in the TestKit - Watch and Unwatch have always been secretly asynchronous, which is why tests like this one failed:

[Fact]
        public async Task Routers_in_general_must_evict_terminated_routees()
        {
            var router = Sys.ActorOf(new RoundRobinPool(2).Props(Props.Create<Echo>()));
            router.Tell("");
            router.Tell("");

            var c1 = await ExpectMsgAsync<IActorRef>();
            var c2 = await ExpectMsgAsync<IActorRef>();

            Watch(router);
            Watch(c2);
            Sys.Stop(c2);
            (await ExpectTerminatedAsync(c2)).ExistenceConfirmed.Should().BeTrue();

            // it might take a while until the Router has actually processed the Terminated message
            await AwaitConditionAsync(async () =>
            {
                router.Tell("");
                router.Tell("");

                var res = await ReceiveWhileAsync(100.Milliseconds(), x =>
                {
                    if (x is IActorRef actorRef)
                        return actorRef;

                    return null;
                }, msgs: 2).ToListAsync();

                return res.Count == 2 && res.All(c => c.Equals(c1));
            });

            Sys.Stop(c1);
            (await ExpectTerminatedAsync(router)).ExistenceConfirmed.Should().BeTrue();
        }

Failed on (await ExpectTerminatedAsync(c2)).ExistenceConfirmed.Should().BeTrue();, which can only mean the actor was dead before the TestActor had a chance to go through.

Originally posted by @Aaronontheweb in #7037 (comment)

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 confirmed bug
Projects
None yet
1 participant