Skip to content

Commit

Permalink
Merge pull request #1874 from Danthar/becometests
Browse files Browse the repository at this point in the history
Added testcase for Become in Become scenario
  • Loading branch information
Aaronontheweb committed Apr 11, 2016
2 parents 25a1ede + a3a1572 commit e84c907
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions src/core/Akka.Tests/Actor/ActorBecomeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Become3Actor>("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)
Expand Down Expand Up @@ -169,6 +190,39 @@ private void OnReceive3(object message)
}
}
}

private class Become3Actor : ReceiveActor
{
public Become3Actor()
{
Become(A);
}

public void A()
{
Receive<string>(s => {
Sender.Tell("A says: " + s);
});
Receive<bool>(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<string>(s => {
Sender.Tell("B says: " + s);
});
Receive<bool>(s => {
Sender.Tell("B says: " + s);
});
Receive<int>(s => {
Sender.Tell("B says: " + s);
});
}
}
}
}

0 comments on commit e84c907

Please sign in to comment.