Skip to content

Commit

Permalink
Convert Akka.Remote.Tests to async - Transport.DotNettyTransportShutd…
Browse files Browse the repository at this point in the history
…ownSpec (#5896)
  • Loading branch information
Arkatufus authored Apr 29, 2022
1 parent 14d5ae9 commit 8ca0252
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 26 deletions.
5 changes: 4 additions & 1 deletion src/core/Akka.Remote.Tests/RemotingTerminatorSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -105,6 +107,7 @@ await EventFilter.Exception<ShutDownAssociation>().ExpectAsync(0,
async () =>
{
_sys2 = ActorSystem.Create("System2", RemoteConfig);
InitializeLogger(_sys2);
var sys2Address = RARP.For(_sys2).Provider.DefaultAddress;

// open an association via remote deployment
Expand All @@ -113,7 +116,7 @@ await EventFilter.Exception<ShutDownAssociation>().ExpectAsync(0,
Watch(associated);

// verify that the association is open (don't terminate until handshake is finished)
associated.Ask<ActorIdentity>(new Identify("foo"), RemainingOrDefault).Result.MessageId.ShouldBe("foo");
(await associated.Ask<ActorIdentity>(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.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<InboundAssociation>().Association; // wait for the inbound association handle to show up
var inboundHandle = (await p2.ExpectMsgAsync<InboundAssociation>()).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<Disassociated>();
AwaitCondition(() => t1.ConnectionGroup.Count == 1);
AwaitCondition(() => t2.ConnectionGroup.Count == 1);
await p1.ExpectMsgAsync<Disassociated>();
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();
Expand Down Expand Up @@ -142,22 +142,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<InboundAssociation>().Association; // wait for the inbound association handle to show up
var inboundHandle = (await p2.ExpectMsgAsync<InboundAssociation>()).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));

// shutdown remoting on t1
await t1.Shutdown();

p2.ExpectMsg<Disassociated>();
await p2.ExpectMsgAsync<Disassociated>();
// 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();
Expand Down Expand Up @@ -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<InboundAssociation>().Association; // wait for the inbound association handle to show up
var inboundHandle = (await p2.ExpectMsgAsync<InboundAssociation>()).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();
Expand Down Expand Up @@ -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<InboundAssociation>().Association; // wait for the inbound association handle to show up
var inboundHandle = (await p2.ExpectMsgAsync<InboundAssociation>()).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));
Expand All @@ -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();
Expand Down Expand Up @@ -290,7 +290,7 @@ await Assert.ThrowsAsync<InvalidAssociationException>(async () =>
});


AwaitCondition(() => t1.ConnectionGroup.Count == 1);
await AwaitConditionAsync(() => t1.ConnectionGroup.Count == 1);
}
finally
{
Expand Down

0 comments on commit 8ca0252

Please sign in to comment.