Skip to content

Commit

Permalink
Annotated connection resume and recovery spec
Browse files Browse the repository at this point in the history
  • Loading branch information
sacOO7 committed Sep 8, 2023
1 parent b250e61 commit b83a9c9
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/IO.Ably.Shared/Realtime/Connection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public string CreateRecoveryKey()
/// message and, in the failed state in particular, provides diagnostic
/// error information.
/// </summary>
public ErrorInfo ErrorReason => InnerState.ErrorReason;
public ErrorInfo ErrorReason => InnerState.ErrorReason; // RTN15c7

/// <summary>
/// Gets the currently used Host.
Expand Down
4 changes: 0 additions & 4 deletions src/IO.Ably.Shared/Realtime/Workflows/RealtimeState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 6 additions & 4 deletions src/IO.Ably.Shared/Realtime/Workflows/RealtimeWorkflow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
{
Expand All @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using FluentAssertions;
using System.IO;
using FluentAssertions;
using System.Threading.Tasks;
using Xunit;
using Xunit.Abstractions;
Expand All @@ -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)
Expand Down

0 comments on commit b83a9c9

Please sign in to comment.