diff --git a/src/core/Akka.Tests/Actor/ActorBecomeTests.cs b/src/core/Akka.Tests/Actor/ActorBecomeTests.cs index e0c855356f4..8f64d3ca0cf 100644 --- a/src/core/Akka.Tests/Actor/ActorBecomeTests.cs +++ b/src/core/Akka.Tests/Actor/ActorBecomeTests.cs @@ -82,6 +82,27 @@ public void Given_actor_that_has_called_default_Become_without_overwriting_previ ExpectMsg("2:hello"); } + [Fact] + public void Given_actor_that_calls_become_in_the_become_handler_only_first_become_receive_set_is_used() { + var system = ActorSystem.Create("test"); + + //Given, this actor calls become(A) inside A() it calls Become(B); + var actor = system.ActorOf("become"); + + //only the handler set of A() should be active + + actor.Tell("hi", TestActor); + actor.Tell(true, TestActor); + + //which means this message should never be handled, because only B() has a receive for this. + actor.Tell(2, TestActor); + + ExpectMsg("A says: hi"); + ExpectMsg("A says: True"); + //we dont expect any further messages + this.ExpectNoMsg(); + } + private class BecomeActor : UntypedActor { protected override void OnReceive(object message) @@ -169,6 +190,39 @@ private void OnReceive3(object message) } } } + + private class Become3Actor : ReceiveActor + { + public Become3Actor() + { + Become(A); + } + + public void A() + { + Receive(s => { + Sender.Tell("A says: " + s); + }); + Receive(s => { + Sender.Tell("A says: " + s); + }); + //calling become before or after setting up the receive handlers makes no difference. + Become(B); + } + + public void B() + { + Receive(s => { + Sender.Tell("B says: " + s); + }); + Receive(s => { + Sender.Tell("B says: " + s); + }); + Receive(s => { + Sender.Tell("B says: " + s); + }); + } + } } }