diff --git a/src/IO.Ably.Tests.Shared/Realtime/ConnectionSandBoxSpecs.cs b/src/IO.Ably.Tests.Shared/Realtime/ConnectionSandBoxSpecs.cs index 1655f9783..3cd5c62eb 100644 --- a/src/IO.Ably.Tests.Shared/Realtime/ConnectionSandBoxSpecs.cs +++ b/src/IO.Ably.Tests.Shared/Realtime/ConnectionSandBoxSpecs.cs @@ -626,49 +626,56 @@ public async Task ResumeRequest_ConnectedProtocolMessageWithSameOrNewConnectionI var channelName = "RTN15c6.RTN15c7.".AddRandomSuffix(); const int channelCount = 5; await client.WaitForState(ConnectionState.Connected); + var connectionId = client.Connection.Id; var channels = new List(); for (var i = 0; i < channelCount; i++) { - channels.Add(client.Channels.Get($"{channelName}_{i}") as RealtimeChannel); + var channel = client.Channels.Get($"{channelName}_{i}"); + await channel.AttachAsync(); + channels.Add(channel as RealtimeChannel); } - List attachedChannels = new List(); - - await WaitForMultiple(channelCount, partialDone => - { - foreach (var channel in channels) - { - channel.Attach(); - channel.Once(ChannelEvent.Attached, _ => - { - partialDone(); - }); - } - }); - client.State.Connection.Id = string.Empty; - client.State.Connection.Key = "xxxxx!xxxxxxx-xxxxxxxx-xxxxxxxx"; // invalid connection key for next resume request - client.GetTestTransport().Close(false); - - // Should send message on the channel so it gets into pending state - - await WaitForMultiple(channelCount, partialDone => + async Task CheckForAttachedChannelsAfterResume() { - foreach (var channel in channels) + var attachedChannels = new List(); + await WaitForMultiple(channelCount, partialDone => { - channel.Once(ChannelEvent.Attaching, _ => + foreach (var channel in channels) { - channel.Once(ChannelEvent.Attached, _ => + channel.Once(ChannelEvent.Attaching, _ => { - attachedChannels.Add(channel); - partialDone(); + channel.Once(ChannelEvent.Attached, _ => + { + attachedChannels.Add(channel); + partialDone(); + }); }); - }); - } - }); + } + }); + attachedChannels.Should().HaveCount(channelCount); + + // TODO - check for processed pending messages + } + + client.GetTestTransport().Close(false); + await CheckForAttachedChannelsAfterResume(); + client.GetTestTransport().ProtocolMessagesReceived.Count(x => x.Action == ProtocolMessage.MessageAction.Connected).Should().Be(1); // For every new transport, list is reset + var connectedProtocolMessage = client.GetTestTransport().ProtocolMessagesReceived.First(x => x.Action == ProtocolMessage.MessageAction.Connected); + connectedProtocolMessage.ConnectionId.Should().Be(connectionId); // resume successful - RTN15c6 + connectedProtocolMessage.Error.Should().BeNull(); + client.Connection.ErrorReason.Should().BeNull(); - // Check if channels have processed pending queued messages - attachedChannels.Should().HaveCount(channelCount); + client.State.Connection.Id = string.Empty; + client.State.Connection.Key = "xxxxx!xxxxxxx-xxxxxxxx-xxxxxxxx"; // invalid connection key for next resume request + client.GetTestTransport().Close(false); + await CheckForAttachedChannelsAfterResume(); + client.GetTestTransport().ProtocolMessagesReceived.Count(x => x.Action == ProtocolMessage.MessageAction.Connected).Should().Be(1); // For every new transport, list is reset + connectedProtocolMessage = client.GetTestTransport().ProtocolMessagesReceived.First(x => x.Action == ProtocolMessage.MessageAction.Connected); + connectedProtocolMessage.ConnectionId.Should().NotBe(connectionId); // resume unsuccessful - RTN15c7 + connectedProtocolMessage.Error.Should().NotBeNull(); + client.Connection.ErrorReason.ToString().Should().Be(connectedProtocolMessage.Error.ToString()); + client.Connection.ErrorReason.Code.Should().Be(ErrorCodes.InvalidFormatForConnectionId); client.Close(); }