From e3447168330b41f0ec45a0a12a29b13fde008380 Mon Sep 17 00:00:00 2001 From: Gregorius Soedharmo Date: Thu, 28 Apr 2022 02:01:22 +0700 Subject: [PATCH 1/2] Convert Akka.Remote.Tests to async - Transport.DotNettyTransportShutdownSpec --- .../DotNettyTransportShutdownSpec.cs | 50 +++++++++---------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/src/core/Akka.Remote.Tests/Transport/DotNettyTransportShutdownSpec.cs b/src/core/Akka.Remote.Tests/Transport/DotNettyTransportShutdownSpec.cs index 12276cd952e..dd92877e15f 100644 --- a/src/core/Akka.Remote.Tests/Transport/DotNettyTransportShutdownSpec.cs +++ b/src/core/Akka.Remote.Tests/Transport/DotNettyTransportShutdownSpec.cs @@ -92,22 +92,22 @@ public async Task DotNettyTcpTransport_should_cleanly_terminate_active_endpoints // t1 --> t2 association var handle = await t1.Associate(c2.Item1); handle.ReadHandlerSource.SetResult(new ActorHandleEventListener(p1)); - var inboundHandle = p2.ExpectMsg().Association; // wait for the inbound association handle to show up + var inboundHandle = (await p2.ExpectMsgAsync()).Association; // wait for the inbound association handle to show up inboundHandle.ReadHandlerSource.SetResult(new ActorHandleEventListener(p2)); - AwaitCondition(() => t1.ConnectionGroup.Count == 2); - AwaitCondition(() => t2.ConnectionGroup.Count == 2); + await AwaitConditionAsync(() => t1.ConnectionGroup.Count == 2); + await AwaitConditionAsync(() => t2.ConnectionGroup.Count == 2); var chan1 = t1.ConnectionGroup.Single(x => !x.Id.Equals(t1.ServerChannel.Id)); var chan2 = t2.ConnectionGroup.Single(x => !x.Id.Equals(t2.ServerChannel.Id)); // force a disassociation - handle.Disassociate(); + handle.Disassociate("Dissociation test", Log); // verify that the connections are terminated - p1.ExpectMsg(); - AwaitCondition(() => t1.ConnectionGroup.Count == 1); - AwaitCondition(() => t2.ConnectionGroup.Count == 1); + await p1.ExpectMsgAsync(); + await AwaitConditionAsync(() => t1.ConnectionGroup.Count == 1); + await AwaitConditionAsync(() => t2.ConnectionGroup.Count == 1); // verify that the connection channels were terminated on both ends chan1.CloseCompletion.IsCompleted.Should().BeTrue(); @@ -142,11 +142,11 @@ public async Task DotNettyTcpTransport_should_cleanly_terminate_active_endpoints // t1 --> t2 association var handle = await t1.Associate(c2.Item1); handle.ReadHandlerSource.SetResult(new ActorHandleEventListener(p1)); - var inboundHandle = p2.ExpectMsg().Association; // wait for the inbound association handle to show up + var inboundHandle = (await p2.ExpectMsgAsync()).Association; // wait for the inbound association handle to show up inboundHandle.ReadHandlerSource.SetResult(new ActorHandleEventListener(p2)); - AwaitCondition(() => t1.ConnectionGroup.Count == 2); - AwaitCondition(() => t2.ConnectionGroup.Count == 2); + await AwaitConditionAsync(() => t1.ConnectionGroup.Count == 2); + await AwaitConditionAsync(() => t2.ConnectionGroup.Count == 2); var chan1 = t1.ConnectionGroup.Single(x => !x.Id.Equals(t1.ServerChannel.Id)); var chan2 = t2.ConnectionGroup.Single(x => !x.Id.Equals(t2.ServerChannel.Id)); @@ -154,10 +154,10 @@ public async Task DotNettyTcpTransport_should_cleanly_terminate_active_endpoints // shutdown remoting on t1 await t1.Shutdown(); - p2.ExpectMsg(); + await p2.ExpectMsgAsync(); // verify that the connections are terminated - AwaitCondition(() => t1.ConnectionGroup.Count == 0, null, message: $"Expected 0 open connection but found {t1.ConnectionGroup.Count}"); - AwaitCondition(() => t2.ConnectionGroup.Count == 1, null,message: $"Expected 1 open connection but found {t2.ConnectionGroup.Count}"); + await AwaitConditionAsync(() => t1.ConnectionGroup.Count == 0, null, message: $"Expected 0 open connection but found {t1.ConnectionGroup.Count}"); + await AwaitConditionAsync(() => t2.ConnectionGroup.Count == 1, null,message: $"Expected 1 open connection but found {t2.ConnectionGroup.Count}"); // verify that the connection channels were terminated on both ends chan1.CloseCompletion.IsCompleted.Should().BeTrue(); @@ -192,21 +192,21 @@ public async Task DotNettyTcpTransport_should_cleanly_terminate_active_endpoints // t1 --> t2 association var handle = await t1.Associate(c2.Item1); handle.ReadHandlerSource.SetResult(new ActorHandleEventListener(p1)); - var inboundHandle = p2.ExpectMsg().Association; // wait for the inbound association handle to show up + var inboundHandle = (await p2.ExpectMsgAsync()).Association; // wait for the inbound association handle to show up inboundHandle.ReadHandlerSource.SetResult(new ActorHandleEventListener(p2)); - AwaitCondition(() => t1.ConnectionGroup.Count == 2); - AwaitCondition(() => t2.ConnectionGroup.Count == 2); + await AwaitConditionAsync(() => t1.ConnectionGroup.Count == 2); + await AwaitConditionAsync(() => t2.ConnectionGroup.Count == 2); var chan1 = t1.ConnectionGroup.Single(x => !x.Id.Equals(t1.ServerChannel.Id)); var chan2 = t2.ConnectionGroup.Single(x => !x.Id.Equals(t2.ServerChannel.Id)); // force a disassociation - inboundHandle.Disassociate(); + inboundHandle.Disassociate("Dissociation test", Log); // verify that the connections are terminated - AwaitCondition(() => t1.ConnectionGroup.Count == 1, null, message: $"Expected 1 open connection but found {t1.ConnectionGroup.Count}"); - AwaitCondition(() => t2.ConnectionGroup.Count == 1, null, message: $"Expected 1 open connection but found {t2.ConnectionGroup.Count}"); + await AwaitConditionAsync(() => t1.ConnectionGroup.Count == 1, null, message: $"Expected 1 open connection but found {t1.ConnectionGroup.Count}"); + await AwaitConditionAsync(() => t2.ConnectionGroup.Count == 1, null, message: $"Expected 1 open connection but found {t2.ConnectionGroup.Count}"); // verify that the connection channels were terminated on both ends chan1.CloseCompletion.IsCompleted.Should().BeTrue(); @@ -241,11 +241,11 @@ public async Task DotNettyTcpTransport_should_cleanly_terminate_active_endpoints // t1 --> t2 association var handle = await t1.Associate(c2.Item1); handle.ReadHandlerSource.SetResult(new ActorHandleEventListener(p1)); - var inboundHandle = p2.ExpectMsg().Association; // wait for the inbound association handle to show up + var inboundHandle = (await p2.ExpectMsgAsync()).Association; // wait for the inbound association handle to show up inboundHandle.ReadHandlerSource.SetResult(new ActorHandleEventListener(p2)); - AwaitCondition(() => t1.ConnectionGroup.Count == 2); - AwaitCondition(() => t2.ConnectionGroup.Count == 2); + await AwaitConditionAsync(() => t1.ConnectionGroup.Count == 2); + await AwaitConditionAsync(() => t2.ConnectionGroup.Count == 2); var chan1 = t1.ConnectionGroup.Single(x => !x.Id.Equals(t1.ServerChannel.Id)); var chan2 = t2.ConnectionGroup.Single(x => !x.Id.Equals(t2.ServerChannel.Id)); @@ -254,8 +254,8 @@ public async Task DotNettyTcpTransport_should_cleanly_terminate_active_endpoints await t2.Shutdown(); // verify that the connections are terminated - AwaitCondition(() => t1.ConnectionGroup.Count == 1, null, message: $"Expected 1 open connection but found {t1.ConnectionGroup.Count}"); - AwaitCondition(() => t2.ConnectionGroup.Count == 0, null, message: $"Expected 0 open connection but found {t2.ConnectionGroup.Count}"); + await AwaitConditionAsync(() => t1.ConnectionGroup.Count == 1, null, message: $"Expected 1 open connection but found {t1.ConnectionGroup.Count}"); + await AwaitConditionAsync(() => t2.ConnectionGroup.Count == 0, null, message: $"Expected 0 open connection but found {t2.ConnectionGroup.Count}"); // verify that the connection channels were terminated on both ends chan1.CloseCompletion.IsCompleted.Should().BeTrue(); @@ -290,7 +290,7 @@ await Assert.ThrowsAsync(async () => }); - AwaitCondition(() => t1.ConnectionGroup.Count == 1); + await AwaitConditionAsync(() => t1.ConnectionGroup.Count == 1); } finally { From 8e207f56014b28b0bb66959ce21291011632f33b Mon Sep 17 00:00:00 2001 From: Gregorius Soedharmo Date: Sat, 30 Apr 2022 04:52:33 +0700 Subject: [PATCH 2/2] Add logging to the second system for easier debugging (cherry picked from commit 793b29e22dfc44d7e2be13d1b30e2ee860172cb6) --- src/core/Akka.Remote.Tests/RemotingTerminatorSpecs.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/core/Akka.Remote.Tests/RemotingTerminatorSpecs.cs b/src/core/Akka.Remote.Tests/RemotingTerminatorSpecs.cs index 89bfd43d2a0..8794d05c2a3 100644 --- a/src/core/Akka.Remote.Tests/RemotingTerminatorSpecs.cs +++ b/src/core/Akka.Remote.Tests/RemotingTerminatorSpecs.cs @@ -58,6 +58,7 @@ await WithinAsync(TimeSpan.FromSeconds(10), async () => public async Task RemotingTerminator_should_shutdown_promptly_with_some_associations() { _sys2 = ActorSystem.Create("System2", RemoteConfig); + InitializeLogger(_sys2); var sys2Address = RARP.For(_sys2).Provider.DefaultAddress; // open an association @@ -78,6 +79,7 @@ public async Task RemotingTerminator_should_shutdown_promptly_with_some_associat public async Task RemotingTerminator_should_shutdown_properly_with_remotely_deployed_actor() { _sys2 = ActorSystem.Create("System2", RemoteConfig); + InitializeLogger(_sys2); var sys2Address = RARP.For(_sys2).Provider.DefaultAddress; // open an association via remote deployment @@ -105,6 +107,7 @@ await EventFilter.Exception().ExpectAsync(0, async () => { _sys2 = ActorSystem.Create("System2", RemoteConfig); + InitializeLogger(_sys2); var sys2Address = RARP.For(_sys2).Provider.DefaultAddress; // open an association via remote deployment @@ -113,7 +116,7 @@ await EventFilter.Exception().ExpectAsync(0, Watch(associated); // verify that the association is open (don't terminate until handshake is finished) - associated.Ask(new Identify("foo"), RemainingOrDefault).Result.MessageId.ShouldBe("foo"); + (await associated.Ask(new Identify("foo"), RemainingOrDefault)).MessageId.ShouldBe("foo"); // terminate the DEPLOYED system Assert.True(await _sys2.Terminate().AwaitWithTimeout(10.Seconds()), "Expected to terminate within 10 seconds, but didn't.");