From 396bfc1917e0fec2bcc9cfadc711f0355827605d Mon Sep 17 00:00:00 2001 From: Gregorius Soedharmo Date: Fri, 29 Apr 2022 23:00:29 +0700 Subject: [PATCH] Convert Akka.Remote.Tests to async - RemoteMessageLocalDeliverySpec (#5889) Co-authored-by: Aaron Stannard --- .../RemoteMessageLocalDeliverySpec.cs | 35 +++++++++---------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/src/core/Akka.Remote.Tests/RemoteMessageLocalDeliverySpec.cs b/src/core/Akka.Remote.Tests/RemoteMessageLocalDeliverySpec.cs index 84421b9a364..13fe53f209b 100644 --- a/src/core/Akka.Remote.Tests/RemoteMessageLocalDeliverySpec.cs +++ b/src/core/Akka.Remote.Tests/RemoteMessageLocalDeliverySpec.cs @@ -14,6 +14,7 @@ using Akka.Configuration; using Akka.Remote.Transport; using Akka.TestKit; +using Akka.TestKit.Extensions; using Akka.TestKit.TestActors; using Xunit; using Xunit.Abstractions; @@ -71,12 +72,12 @@ public void RemoteActorRefProvider_should_correctly_resolve_valid_LocalActorRef_ } [Fact] - public void RemoteActorRefProvider_should_correctly_resolve_valid_LocalActorRef_from_second_remote_system() + public async Task RemoteActorRefProvider_should_correctly_resolve_valid_LocalActorRef_from_second_remote_system() { - var sys2 = ActorSystem.Create("Sys2", RemoteConfiguration); + var sys2 = ActorSystem.Create("Sys2", RemoteConfiguration); try { - Within(TimeSpan.FromSeconds(15), () => + await WithinAsync(TimeSpan.FromSeconds(15), async () => { var actorRef = sys2.ActorOf(BlackHoleActor.Props, "myActor"); var sys2Address = RARP.For(sys2).Provider.DefaultAddress; @@ -86,33 +87,31 @@ public void RemoteActorRefProvider_should_correctly_resolve_valid_LocalActorRef_ var remoteActorRef = Sys.ActorSelection(actorPath).ResolveOne(TimeSpan.FromSeconds(3)).Result; // disconnect us from the second actorsystem - var mc = - RARP.For(Sys) - .Provider.Transport.ManagementCommand(new SetThrottle(sys2Address, - ThrottleTransportAdapter.Direction.Both, Blackhole.Instance)); - Assert.True(mc.Wait(TimeSpan.FromSeconds(3))); + Assert.True(await RARP.For(Sys) + .Provider.Transport.ManagementCommand(new SetThrottle(sys2Address, + ThrottleTransportAdapter.Direction.Both, Blackhole.Instance)) + .WithTimeout(TimeSpan.FromSeconds(3))); // start deathwatch (won't be delivered initially) Watch(remoteActorRef); - Task.Delay(TimeSpan.FromSeconds(3)).Wait(); // if we delay the initial send, this spec will fail + await Task.Delay(TimeSpan.FromSeconds(3)); // if we delay the initial send, this spec will fail - var mc2 = - RARP.For(Sys) - .Provider.Transport.ManagementCommand(new SetThrottle(sys2Address, - ThrottleTransportAdapter.Direction.Both, Unthrottled.Instance)); - Assert.True(mc2.Wait(TimeSpan.FromSeconds(3))); + Assert.True(await RARP.For(Sys) + .Provider.Transport.ManagementCommand(new SetThrottle(sys2Address, + ThrottleTransportAdapter.Direction.Both, Unthrottled.Instance)) + .WithTimeout(TimeSpan.FromSeconds(3))); // fire off another non-system message - var ai = - Sys.ActorSelection(actorPath).Ask(new Identify(null), TimeSpan.FromSeconds(3)).Result; + var ai = + await Sys.ActorSelection(actorPath).Ask(new Identify(null), TimeSpan.FromSeconds(3)); remoteActorRef.Tell(PoisonPill.Instance); // WATCH should be applied first - ExpectTerminated(remoteActorRef); + await ExpectTerminatedAsync(remoteActorRef); }); } finally { - Assert.True(sys2.Terminate().Wait(TimeSpan.FromSeconds(5))); + await ShutdownAsync(sys2); } } }