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

Port Akka.Tests.Actor tests to async/await #5757

Merged
merged 2 commits into from
Mar 28, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions src/core/Akka.Tests/Actor/ActorBecomeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// </copyright>
//-----------------------------------------------------------------------

using System.Threading.Tasks;
using Akka.Actor;
using Akka.TestKit;
using Xunit;
Expand All @@ -16,7 +17,7 @@ public class ActorBecomeTests : AkkaSpec
{

[Fact]
public void When_calling_become_Then_the_new_handler_is_used()
public async Task When_calling_become_Then_the_new_handler_is_used()
{

//Given
Expand All @@ -28,12 +29,12 @@ public void When_calling_become_Then_the_new_handler_is_used()
actor.Tell("hello", TestActor);

//Then
ExpectMsg("2:hello");
await ExpectMsgAsync("2:hello");
}


[Fact]
public void Given_actor_that_has_called_default_Become_twice_When_calling_unbecome_Then_the_default_handler_is_used_and_not_the_last_handler()
public async Task Given_actor_that_has_called_default_Become_twice_When_calling_unbecome_Then_the_default_handler_is_used_and_not_the_last_handler()
{
//Calling Become() does not persist the current handler, it just overwrites it, so when we call Unbecome(),
//no matter how many times, there is no persisted handler to revert to, so we'll end up with the default one
Expand All @@ -54,12 +55,12 @@ public void Given_actor_that_has_called_default_Become_twice_When_calling_unbeco
actor.Tell("hello", TestActor);

//Then
ExpectMsg("1:hello");
await ExpectMsgAsync("1:hello");
}


[Fact]
public void Given_actor_that_has_called_default_Become_without_overwriting_previous_handler_When_calling_unbecome_Then_the_previous_handler_is_used()
public async Task Given_actor_that_has_called_default_Become_without_overwriting_previous_handler_When_calling_unbecome_Then_the_previous_handler_is_used()
{
//Calling Become() does not persist the current handler, it just overwrites it, so when we call Unbecome(),
//no matter how many times, there is no persisted handler to revert to, so we'll end up with the default one
Expand All @@ -79,11 +80,11 @@ public void Given_actor_that_has_called_default_Become_without_overwriting_previ
actor.Tell("hello", TestActor);

//Then
ExpectMsg("2:hello");
await ExpectMsgAsync("2:hello");
}

[Fact]
public void Given_actor_that_calls_become_in_the_become_handler_only_first_become_receive_set_is_used() {
public async Task 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);
Expand All @@ -97,10 +98,10 @@ public void Given_actor_that_calls_become_in_the_become_handler_only_first_becom
//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");
await ExpectMsgAsync("A says: hi");
await ExpectMsgAsync("A says: True");
//we dont expect any further messages
this.ExpectNoMsg();
await ExpectNoMsgAsync(default);
}

private class BecomeActor : UntypedActor
Expand Down