diff --git a/src/IO.Ably.Tests.Shared/Realtime/ConnectionSpecs/ConnectionRecoverySpecs.cs b/src/IO.Ably.Tests.Shared/Realtime/ConnectionSpecs/ConnectionRecoverySpecs.cs index 928cfc849..25d400647 100644 --- a/src/IO.Ably.Tests.Shared/Realtime/ConnectionSpecs/ConnectionRecoverySpecs.cs +++ b/src/IO.Ably.Tests.Shared/Realtime/ConnectionSpecs/ConnectionRecoverySpecs.cs @@ -1,8 +1,10 @@ +using System.Collections.Generic; using System.IO; using System.Linq; using System.Threading.Tasks; using FluentAssertions; using IO.Ably.Realtime; +using IO.Ably.Realtime.Workflow; using IO.Ably.Tests.Infrastructure; using IO.Ably.Types; using Xunit; @@ -75,17 +77,17 @@ public async Task RecoveryKey_MsgSerialShouldNotBeSentToAblyButShouldBeSetOnConn { var recoveryKey = "{\"connectionKey\":\"uniqueKey\",\"msgSerial\":45,\"channelSerials\":{\"channel1\":\"1\",\"channel2\":\"2\",\"channel3\":\"3\"}}"; - FakeTransportFactory.InitialiseFakeTransport = - transport => transport.OnConnectChangeStateToConnected = false; var client = GetClientWithFakeTransport(options => { options.Recover = recoveryKey; }); var transportParams = await client.ConnectionManager.CreateTransportParameters("https://realtime.ably.io"); var paramsDict = transportParams.GetParams(); paramsDict.ContainsKey("recover").Should().BeTrue(); paramsDict["recover"].Should().Be("uniqueKey"); - paramsDict.ContainsKey("msg_serial").Should().BeFalse(); - await new ConditionalAwaiter(() => client.Connection.MessageSerial == 45); + client.FakeProtocolMessageReceived(ConnectedProtocolMessage); + await client.WaitForState(ConnectionState.Connected); + + client.Connection.MessageSerial.Should().Be(45); client.Channels.Count().Should().Be(3); var channelCounter = 1; foreach (var realtimeChannel in client.Channels.OrderBy(channel => channel.Name)) @@ -94,6 +96,27 @@ public async Task RecoveryKey_MsgSerialShouldNotBeSentToAblyButShouldBeSetOnConn realtimeChannel.Properties.ChannelSerial.Should().Be($"{channelCounter}"); channelCounter++; } + + // Recover should be set to null once used + client.Options.Recover.Should().BeNull(); + + client.Connection.InnerState.MessageSerial = 0; + client.Channels.ReleaseAll(); + + client.ExecuteCommand(SetDisconnectedStateCommand.Create(null, true)); + await client.WaitForState(ConnectionState.Disconnected); + await client.WaitForState(ConnectionState.Connecting); + + transportParams = await client.ConnectionManager.CreateTransportParameters("https://realtime.ably.io"); + paramsDict = transportParams.GetParams(); + paramsDict.ContainsKey("recover").Should().BeFalse(); // recover param should be empty for next attempt + + client.FakeProtocolMessageReceived(ConnectedProtocolMessage); + await client.WaitForState(ConnectionState.Connected); + + // Recover options shouldn't be used for next retry + client.Connection.MessageSerial.Should().Be(0); + client.Channels.Count().Should().Be(0); } public ConnectionRecoverySpecs(ITestOutputHelper output)