diff --git a/src/IO.Ably.Shared/Realtime/Connection.cs b/src/IO.Ably.Shared/Realtime/Connection.cs index b96324df2..5eae16db9 100644 --- a/src/IO.Ably.Shared/Realtime/Connection.cs +++ b/src/IO.Ably.Shared/Realtime/Connection.cs @@ -209,7 +209,7 @@ public string CreateRecoveryKey() /// message and, in the failed state in particular, provides diagnostic /// error information. /// - public ErrorInfo ErrorReason => InnerState.ErrorReason; + public ErrorInfo ErrorReason => InnerState.ErrorReason; // RTN15c7 /// /// Gets the currently used Host. diff --git a/src/IO.Ably.Shared/Realtime/Workflows/RealtimeState.cs b/src/IO.Ably.Shared/Realtime/Workflows/RealtimeState.cs index 36c6366bd..07515f861 100644 --- a/src/IO.Ably.Shared/Realtime/Workflows/RealtimeState.cs +++ b/src/IO.Ably.Shared/Realtime/Workflows/RealtimeState.cs @@ -87,10 +87,6 @@ public void Update(ConnectionInfo info) } } - // RTN16d - public bool IsResumed(ConnectionInfo info) => - Key.IsNotEmpty() && Id == info.ConnectionId; - public void ClearKeyAndId() { Id = string.Empty; diff --git a/src/IO.Ably.Shared/Realtime/Workflows/RealtimeWorkflow.cs b/src/IO.Ably.Shared/Realtime/Workflows/RealtimeWorkflow.cs index 6a312e321..b3968b941 100644 --- a/src/IO.Ably.Shared/Realtime/Workflows/RealtimeWorkflow.cs +++ b/src/IO.Ably.Shared/Realtime/Workflows/RealtimeWorkflow.cs @@ -599,10 +599,12 @@ private void HandleConnectedCommand(SetConnectedStateCommand cmd) { var info = new ConnectionInfo(cmd.Message); - var isConnectionResumeOrRecoverAttempt = State.Connection.Key.IsNotEmpty() || Client.Options.Recover.IsNotEmpty(); // recover will only be used during init, resume will be used for all subsequent requests - var resumeOrRecoverSuccess = State.Connection.IsResumed(info) && cmd.Message.Error == null; // RTN15c6 + // recover is used when set via clientOptions#recover initially, resume will be used for all subsequent requests. + var isConnectionResumeOrRecoverAttempt = State.Connection.Key.IsNotEmpty() || Client.Options.Recover.IsNotEmpty(); - State.Connection.Update(info); + var resumeOrRecoverSuccess = State.Connection.Id == info.ConnectionId && cmd.Message.Error == null; // RTN15c6, RTN16d + + State.Connection.Update(info); // RTN16d, RTN15e if (info.ClientId.IsNotEmpty()) { @@ -615,7 +617,7 @@ private void HandleConnectedCommand(SetConnectedStateCommand cmd) cmd.IsUpdate, Logger); - SetState(connectedState); + SetState(connectedState); // RTN15c7 - if error, set on connection and part of emitted connected event Client.Options.Recover = null; // RTN16k, explicitly setting null so it won't be used for subsequent connection requests diff --git a/src/IO.Ably.Tests.Shared/Realtime/ConnectionSpecs/ConnectionSpecs.cs b/src/IO.Ably.Tests.Shared/Realtime/ConnectionSpecs/ConnectionSpecs.cs index b7f1ac8fa..ebfd6c110 100644 --- a/src/IO.Ably.Tests.Shared/Realtime/ConnectionSpecs/ConnectionSpecs.cs +++ b/src/IO.Ably.Tests.Shared/Realtime/ConnectionSpecs/ConnectionSpecs.cs @@ -1,4 +1,5 @@ -using FluentAssertions; +using System.IO; +using FluentAssertions; using System.Threading.Tasks; using Xunit; using Xunit.Abstractions; @@ -19,14 +20,12 @@ public async Task RecoveryKey_MsgSerialShouldNotBeSentToAblyButShouldBeSetOnConn transport => transport.OnConnectChangeStateToConnected = false; var client = GetClientWithFakeTransport(options => { options.Recover = recoveryKey; }); - await Task.Delay(9000); - client.Connection.MessageSerial.Should().Be(45); - 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(); + client.Connection.MessageSerial.Should().Be(45); } public ConnectionSpecs(ITestOutputHelper output)