From e223c990529621f6940c140417aec5cc6535234c Mon Sep 17 00:00:00 2001 From: Ricardo Pereira Date: Wed, 24 Feb 2016 12:10:07 +0000 Subject: [PATCH 1/2] RTN15g --- ablySpec/RealtimeClientConnection.swift | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/ablySpec/RealtimeClientConnection.swift b/ablySpec/RealtimeClientConnection.swift index 8fadfa687..e3a6d44d3 100644 --- a/ablySpec/RealtimeClientConnection.swift +++ b/ablySpec/RealtimeClientConnection.swift @@ -1391,6 +1391,28 @@ class RealtimeClientConnection: QuickSpec { } + // RTN15g + it("when the connection resume has failed, all channels should be detached with an error reason") { + let options = AblyTests.commonAppSetup() + options.disconnectedRetryTimeout = 1.0 + + let client = ARTRealtime(options: options) + defer { client.close() } + let channel = client.channels.get("test") + + waitUntil(timeout: testTimeout) { done in + channel.attach() { errorInfo in + expect(errorInfo).to(beNil()) + done() + } + } + + client.simulateLostConnectionAndState() + + expect(channel.state).toEventually(equal(ARTRealtimeChannelState.Detached), timeout: testTimeout) + expect(channel.errorReason!.message).to(contain("Unable to recover connection")) + } + } // RTN15 From a4232af71ae9415aeb903725f38292b6ea51b100 Mon Sep 17 00:00:00 2001 From: Ricardo Pereira Date: Wed, 2 Mar 2016 08:34:00 +0000 Subject: [PATCH 2/2] RTN15a: misplaced --- ablySpec/RealtimeClientConnection.swift | 115 ++++++++++++------------ 1 file changed, 55 insertions(+), 60 deletions(-) diff --git a/ablySpec/RealtimeClientConnection.swift b/ablySpec/RealtimeClientConnection.swift index e3a6d44d3..8e69f7a36 100644 --- a/ablySpec/RealtimeClientConnection.swift +++ b/ablySpec/RealtimeClientConnection.swift @@ -1310,6 +1310,61 @@ class RealtimeClientConnection: QuickSpec { // RTN15 context("connection failures once CONNECTED") { + // RTN15a + it("should not receive published messages until the connection reconnects successfully") { + let options = AblyTests.commonAppSetup() + options.autoConnect = false + options.disconnectedRetryTimeout = 1.0 + + let client1 = ARTRealtime(options: options) + defer { client1.close() } + let channel1 = client1.channels.get("test") + + var states = [ARTRealtimeConnectionState]() + client1.connection.on() { stateChange in + states = states + [stateChange!.current] + } + client1.connect() + + let client2 = ARTRealtime(options: options) + client2.connect() + defer { client2.close() } + let channel2 = client2.channels.get("test") + + channel1.subscribe { message in + fail("Shouldn't receive the messsage") + } + + expect(channel1.state).toEventually(equal(ARTRealtimeChannelState.Attached), timeout: testTimeout) + + let firstConnection: (id: String, key: String) = (client1.connection.id!, client1.connection.key!) + + // Connection state cannot be resumed + client1.simulateLostConnectionAndState() + + channel2.publish(nil, data: "message") { errorInfo in + expect(errorInfo).to(beNil()) + } + + waitUntil(timeout: testTimeout) { done in + client1.connection.once(.Connecting) { _ in + expect(client1.resuming).to(beTrue()) + done() + } + } + + waitUntil(timeout: testTimeout) { done in + client1.connection.once(.Connected) { _ in + expect(client1.resuming).to(beFalse()) + expect(client1.connection.id).toNot(equal(firstConnection.id)) + expect(client1.connection.key).toNot(equal(firstConnection.key)) + done() + } + } + + expect(states).to(equal([.Connecting, .Connected, .Disconnected, .Connecting, .Connected])) + } + // RTN15d it("should recover from disconnection and messages should be delivered once the connection is resumed") { let options = AblyTests.commonAppSetup() @@ -1415,66 +1470,6 @@ class RealtimeClientConnection: QuickSpec { } - // RTN15 - context("connection failures once CONNECTED") { - - // RTN15a - it("should not receive published messages until the connection reconnects successfully") { - let options = AblyTests.commonAppSetup() - options.autoConnect = false - options.disconnectedRetryTimeout = 1.0 - - let client1 = ARTRealtime(options: options) - defer { client1.close() } - let channel1 = client1.channels.get("test") - - var states = [ARTRealtimeConnectionState]() - client1.connection.on() { stateChange in - states = states + [stateChange!.current] - } - client1.connect() - - let client2 = ARTRealtime(options: options) - client2.connect() - defer { client2.close() } - let channel2 = client2.channels.get("test") - - channel1.subscribe { message in - fail("Shouldn't receive the messsage") - } - - expect(channel1.state).toEventually(equal(ARTRealtimeChannelState.Attached), timeout: testTimeout) - - let firstConnection: (id: String, key: String) = (client1.connection.id!, client1.connection.key!) - - // Connection state cannot be resumed - client1.simulateLostConnectionAndState() - - channel2.publish(nil, data: "message") { errorInfo in - expect(errorInfo).to(beNil()) - } - - waitUntil(timeout: testTimeout) { done in - client1.connection.once(.Connecting) { _ in - expect(client1.resuming).to(beTrue()) - done() - } - } - - waitUntil(timeout: testTimeout) { done in - client1.connection.once(.Connected) { _ in - expect(client1.resuming).to(beFalse()) - expect(client1.connection.id).toNot(equal(firstConnection.id)) - expect(client1.connection.key).toNot(equal(firstConnection.key)) - done() - } - } - - expect(states).to(equal([.Connecting, .Connected, .Disconnected, .Connecting, .Connected])) - } - - } - // RTN18 context("state change side effects") {