Skip to content

Commit

Permalink
Updated test for new channel attach on resume/recover connection
Browse files Browse the repository at this point in the history
  • Loading branch information
sacOO7 committed Sep 14, 2023
1 parent 6b15097 commit 95d2917
Showing 1 changed file with 59 additions and 7 deletions.
66 changes: 59 additions & 7 deletions src/IO.Ably.Tests.Shared/Realtime/ConnectionSandBoxSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -572,10 +572,10 @@ public async Task ResumeRequest_ConnectedProtocolMessageWithSameConnectionId_Wit
[Theory]
[ProtocolData]
[Trait("spec", "RTN15c7")]
public async Task ResumeRequest_ConnectedProtocolMessageWithNewConnectionId_WithErrorInError(Protocol protocol)
public async Task ResumeRequest_ConnectedProtocolMessageWithResumeFailedShouldEmitErrorOnConnection(Protocol protocol)
{
var client = await GetRealtimeClient(protocol);
var channel = (RealtimeChannel)client.Channels.Get("RTN15c3".AddRandomSuffix());
var channel = (RealtimeChannel)client.Channels.Get("RTN15c7".AddRandomSuffix());
await client.WaitForState(ConnectionState.Connected);
channel.Attach();
await channel.WaitForAttachedState();
Expand All @@ -598,7 +598,7 @@ await WaitFor(done =>

stateChange.Should().NotBeNull();
stateChange.HasError.Should().BeTrue();
stateChange.Reason.Code.Should().Be(80018);
stateChange.Reason.Code.Should().Be(ErrorCodes.InvalidFormatForConnectionId);
stateChange.Reason.Should().Be(client.Connection.ErrorReason);

var protocolMessage = client.GetTestTransport().ProtocolMessagesReceived.FirstOrDefault(x => x.Action == ProtocolMessage.MessageAction.Connected);
Expand All @@ -612,6 +612,58 @@ await WaitFor(done =>
client.Connection.MessageSerial.Should().Be(0);
}

[Theory]
[ProtocolData]
[Trait("spec", "RTN15c6")]
[Trait("spec", "RTN15c7")]
public async Task ResumeRequest_ConnectedProtocolMessageWithNewConnectionId_AttachedAllChannels(Protocol protocol)
{
var client = await GetRealtimeClient(protocol);
var channelName = "RTN15c3".AddRandomSuffix();
const int channelCount = 5;
await client.WaitForState(ConnectionState.Connected);

var channels = new List<RealtimeChannel>();
for (var i = 0; i < channelCount; i++)
{
channels.Add(client.Channels.Get($"{channelName}_{i}") as RealtimeChannel);
}

List<RealtimeChannel> attachedChannels = new List<RealtimeChannel>();

await WaitForMultiple(channelCount, partialDone =>
{
foreach (var channel in channels)
{
channel.Attach();
channel.Once(ChannelEvent.Attached, _ =>
{
partialDone();
});
}
});

client.SimulateLostConnectionAndState();
await client.WaitForState(ConnectionState.Connected);

await WaitForMultiple(channelCount, partialDone =>
{
foreach (var channel in channels)
{
channel.Once(ChannelEvent.Attaching, _ =>
{
channel.Once(ChannelEvent.Attached, _ =>
{
attachedChannels.Add(channel);
partialDone();
});
});
}
});

attachedChannels.Should().HaveCount(channelCount);
}

[Theory(Skip = "Keeps failing")]
[ProtocolData]
[Trait("spec", "RTN15c4")]
Expand Down Expand Up @@ -1005,9 +1057,9 @@ public async Task WithDummyRecoverData_ShouldConnectAndSetAReasonOnTheConnection
var result = ResetEvent.WaitOne(10000);
result.Should().BeTrue("Timeout");
err.Should().NotBeNull();
err.Code.Should().Be(80018);
err.Code.Should().Be(ErrorCodes.InvalidFormatForConnectionId);
client.Connection.MessageSerial.Should().Be(0);
client.Connection.ErrorReason.Code.Should().Be(80018);
client.Connection.ErrorReason.Code.Should().Be(ErrorCodes.InvalidFormatForConnectionId);
}

[Theory]
Expand Down Expand Up @@ -1036,8 +1088,8 @@ public async Task WithIncorrectRecoverData_ShouldFailAndSetAReasonOnTheConnectio
var result = ResetEvent.WaitOne(10000);
result.Should().BeTrue("Timeout");
err.Should().NotBeNull();
err.Code.Should().Be(80018);
client.Connection.ErrorReason.Code.Should().Be(80018);
err.Code.Should().Be(ErrorCodes.InvalidFormatForConnectionId);
client.Connection.ErrorReason.Code.Should().Be(ErrorCodes.InvalidFormatForConnectionId);
client.Connection.State.Should().Be(ConnectionState.Failed);
}

Expand Down

0 comments on commit 95d2917

Please sign in to comment.