Skip to content

Commit

Permalink
Added integration test/connectionSandboxTest for connection recovery
Browse files Browse the repository at this point in the history
  • Loading branch information
sacOO7 committed Sep 18, 2023
1 parent 7236373 commit 575f396
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/IO.Ably.Tests.Shared/Realtime/ConnectionSandBoxSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using FluentAssertions;
using IO.Ably.Realtime;
using IO.Ably.Realtime.Workflow;
using IO.Ably.Shared.Realtime;
using IO.Ably.Tests.Infrastructure;
using IO.Ably.Tests.Shared.Utils;
using IO.Ably.Transport;
Expand Down Expand Up @@ -484,6 +485,49 @@ public async Task ResumeRequest_ShouldReceivePendingMessagesOnceConnectionResume
}
}

[Theory]
[ProtocolData]
[Trait("spec", "RTN16d")]
public async Task RecoverRequest_ShouldInitializeRecoveryContextAndReceiveSameConnectionIdOnRecoverSuccess(Protocol protocol)
{
var client1 = await GetRealtimeClient(protocol);
await client1.WaitForState(ConnectionState.Connected);
var client1ConnectionId = client1.Connection.Id;
for (var i = 0; i < 5; i++)
{
var channel = client1.Channels.Get("RTN16d".AddRandomSuffix());
await channel.AttachAsync();
}

var recoveryKey = client1.Connection.CreateRecoveryKey();
var recoveryKeyContext = RecoveryKeyContext.Decode(recoveryKey);

recoveryKeyContext.ConnectionKey.Should().Be(client1.Connection.Key);
recoveryKeyContext.ChannelSerials.Count.Should().Be(client1.Channels.Count());
recoveryKeyContext.MsgSerial.Should().Be(client1.Connection.MessageSerial);

client1.ExecuteCommand(SetDisconnectedStateCommand.Create(null));

var client2 = await GetRealtimeClient(protocol, (options, _) =>
{
options.Recover = recoveryKey;
});

await client2.WaitForState(ConnectionState.Connected);
client2.Connection.Id.Should().Be(client1ConnectionId);
client2.Connection.MessageSerial.Should().Be(recoveryKeyContext.MsgSerial);
client2.Connection.Key.Should().NotBe(recoveryKeyContext.ConnectionKey);
foreach (var realtimeChannel in client1.Channels)
{
realtimeChannel.Properties.ChannelSerial.Should().Be(recoveryKeyContext.ChannelSerials[realtimeChannel.Name]);
}

client2.Options.Recover.Should().BeNull();

client1.Close();
client2.Close();
}

[Theory]
[ProtocolData]
[Trait("spec", "RTN15e")]
Expand Down

0 comments on commit 575f396

Please sign in to comment.