Skip to content

Commit

Permalink
Convert Akka.Remote.Tests to async - BugFixes.BugFix4384Spec (#5905)
Browse files Browse the repository at this point in the history
  • Loading branch information
Arkatufus authored Apr 29, 2022
1 parent 396bfc1 commit ac223da
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions src/core/Akka.Remote.Tests/BugFixes/BugFix4384Spec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
using Xunit;
using Xunit.Abstractions;

namespace Akka.Tests.Actor
namespace Akka.Remote.Tests.BugFixes
{
public class BugFix4384Spec : TestKit.Xunit2.TestKit
{
Expand Down Expand Up @@ -47,6 +47,14 @@ public BugFix4384Spec(ITestOutputHelper outputHelper) : base(nameof(BugFix4384Sp
InitializeLogger(Sys2);
}

protected override async Task AfterAllAsync()
{
await Task.WhenAll(
base.AfterAllAsync(),
ShutdownAsync(Sys1),
ShutdownAsync(Sys2));
}

[Fact]
public async Task Ask_from_local_actor_without_remote_association_should_work()
{
Expand Down Expand Up @@ -84,24 +92,27 @@ public async Task ConsistentHashingPoolRoutersShouldWorkAsExpectedWithHashMappin
var secondActor = Sys1.ActorOf(act => act.ReceiveAny((o, ctx) => ctx.Sender.Tell(o)), "foo");

Sys2.ActorSelection(new RootActorPath(Sys1Address) / "user" / secondActor.Path.Name).Tell("foo", sys2Probe);
sys2Probe.ExpectMsg("foo");
await sys2Probe.ExpectMsgAsync("foo");

// have ActorSystem2 message it via tell
var sel = Sys2.ActorSelection(new RootActorPath(Sys1Address) / "user" / "router1");
sel.Tell(new HashableString("foo"));
ExpectMsg<HashableString>(str => str.Str.Equals("foo"));
await ExpectMsgAsync<HashableString>(str => str.Str.Equals("foo"));

// have ActorSystem2 message it via Ask
sel.Ask(new Identify("bar2"), TimeSpan.FromSeconds(3)).PipeTo(sys2Probe);
var remoteRouter = sys2Probe.ExpectMsg<ActorIdentity>(x => x.MessageId.Equals("bar2"), TimeSpan.FromSeconds(5)).Subject;
// have ActorSystem2 message it via Ask. Task is intentionally not awaited.
var task = sel.Ask(new Identify("bar2"), TimeSpan.FromSeconds(3)).PipeTo(sys2Probe);
var remoteRouter = (await sys2Probe.ExpectMsgAsync<ActorIdentity>(x => x.MessageId.Equals("bar2"), TimeSpan.FromSeconds(5))).Subject;

var s2Actor = Sys2.ActorOf(act =>
{
act.ReceiveAny((o, ctx) =>
sel.Ask<ActorIdentity>(new Identify(o), TimeSpan.FromSeconds(3)).PipeTo(sys2Probe));
{
// Task is intentionally not awaited.
var task = sel.Ask<ActorIdentity>(new Identify(o), TimeSpan.FromSeconds(3)).PipeTo(sys2Probe);
});
});
s2Actor.Tell("hit");
sys2Probe.ExpectMsg<ActorIdentity>(x => x.MessageId.Equals("hit"), TimeSpan.FromSeconds(5));
await sys2Probe.ExpectMsgAsync<ActorIdentity>(x => x.MessageId.Equals("hit"), TimeSpan.FromSeconds(5));
}

class ReporterActor : ReceiveActor
Expand Down

0 comments on commit ac223da

Please sign in to comment.