From 2c8cdf08c5486871142672358224ecf146ac6236 Mon Sep 17 00:00:00 2001 From: Ricardo Pereira Date: Tue, 26 Apr 2016 20:31:19 +0100 Subject: [PATCH 1/3] RTN13b --- Spec/RealtimeClientConnection.swift | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/Spec/RealtimeClientConnection.swift b/Spec/RealtimeClientConnection.swift index ba2a8fc27..363f9df1d 100644 --- a/Spec/RealtimeClientConnection.swift +++ b/Spec/RealtimeClientConnection.swift @@ -1322,6 +1322,32 @@ class RealtimeClientConnection: QuickSpec { } + // RTN13 + context("Ping") { + + // RTN13b + it("should immediately indicate an error if in the CLOSED or FAILED state") { + let client = AblyTests.newRealtime(AblyTests.commonAppSetup()) + defer { client.close() } + waitUntil(timeout: testTimeout) { done in + client.connection.on(.Connected) { _ in + client.onError(AblyTests.newErrorProtocolMessage()) + done() + } + } + waitUntil(timeout: testTimeout) { done in + client.ping() { error in + expect(error).toNot(beNil()) + let transport = client.transport as! TestProxyTransport + expect(transport.protocolMessagesSent.filter{ $0.action == .Heartbeat }).to(haveCount(1)) + expect(transport.protocolMessagesReceived.filter{ $0.action == .Heartbeat }).to(haveCount(0)) + done() + } + } + } + + } + // RTN14a it("should enter FAILED state when API key is invalid") { let options = AblyTests.commonAppSetup() From d7adcfb43c8cf598bd81a3615a539cb4d0704fa9 Mon Sep 17 00:00:00 2001 From: Ricardo Pereira Date: Tue, 26 Apr 2016 20:31:28 +0100 Subject: [PATCH 2/3] RTN13b: pending --- Spec/RealtimeClientConnection.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Spec/RealtimeClientConnection.swift b/Spec/RealtimeClientConnection.swift index 363f9df1d..2746332e4 100644 --- a/Spec/RealtimeClientConnection.swift +++ b/Spec/RealtimeClientConnection.swift @@ -1326,7 +1326,7 @@ class RealtimeClientConnection: QuickSpec { context("Ping") { // RTN13b - it("should immediately indicate an error if in the CLOSED or FAILED state") { + pending("should immediately indicate an error if in the CLOSED or FAILED state") { let client = AblyTests.newRealtime(AblyTests.commonAppSetup()) defer { client.close() } waitUntil(timeout: testTimeout) { done in From a4c9ec2b04fa3bfe25927ea14f6fa35e583aed26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toni=20C=C3=A1rdenas?= Date: Thu, 28 Apr 2016 19:48:29 +0200 Subject: [PATCH 3/3] Fix RTN13b. --- Source/ARTRealtime.m | 2 +- Spec/RealtimeClientConnection.swift | 53 +++++++++-------------------- 2 files changed, 18 insertions(+), 37 deletions(-) diff --git a/Source/ARTRealtime.m b/Source/ARTRealtime.m index b700686e0..e6d177680 100644 --- a/Source/ARTRealtime.m +++ b/Source/ARTRealtime.m @@ -172,7 +172,7 @@ - (void)ping:(void (^)(ARTErrorInfo *)) cb { case ARTRealtimeClosing: case ARTRealtimeClosed: case ARTRealtimeFailed: - [NSException raise:@"Can't ping a closed or failed connection" format:@"%@:", ARTRealtimeStateToStr(self.connection.state)]; + cb([ARTErrorInfo createWithCode:0 status:ARTStateConnectionFailed message:[NSString stringWithFormat:@"Can't ping a %@ connection", ARTRealtimeStateToStr(self.connection.state)]]); return; case ARTRealtimeConnecting: case ARTRealtimeDisconnected: { diff --git a/Spec/RealtimeClientConnection.swift b/Spec/RealtimeClientConnection.swift index 2746332e4..ac6ccb99a 100644 --- a/Spec/RealtimeClientConnection.swift +++ b/Spec/RealtimeClientConnection.swift @@ -1263,7 +1263,7 @@ class RealtimeClientConnection: QuickSpec { } } - // RTN13b + // RTN13 context("ping") { // RTN13b it("fails if in the INITIALIZED, SUSPENDED, CLOSING, CLOSED or FAILED state") { @@ -1276,34 +1276,41 @@ class RealtimeClientConnection: QuickSpec { client.dispose() } + var error: ARTErrorInfo? + func ping() { + error = nil + client.ping() { error = $0 } + } + expect(client.connection.state).to(equal(ARTRealtimeConnectionState.Initialized)) - expect { client.ping { _ in } }.to(raiseException()) + ping() + expect(error).toNot(beNil()) client.connect() expect(client.connection.state).toEventually(equal(ARTRealtimeConnectionState.Connected), timeout: testTimeout) client.onSuspended() expect(client.connection.state).to(equal(ARTRealtimeConnectionState.Suspended)) - expect { client.ping { _ in } }.to(raiseException()) + ping() + expect(error).toNot(beNil()) expect(client.connection.state).toEventually(equal(ARTRealtimeConnectionState.Connected), timeout: testTimeout) client.close() expect(client.connection.state).to(equal(ARTRealtimeConnectionState.Closing)) - expect { client.ping { _ in } }.to(raiseException()) + ping() + expect(error).toNot(beNil()) expect(client.connection.state).toEventually(equal(ARTRealtimeConnectionState.Closed), timeout: testTimeout) - expect { client.ping { _ in } }.to(raiseException()) + ping() + expect(error).toNot(beNil()) client.onError(AblyTests.newErrorProtocolMessage()) expect(client.connection.state).to(equal(ARTRealtimeConnectionState.Failed)) - expect { client.ping { _ in } }.to(raiseException()) + ping() + expect(error).toNot(beNil()) } - } - - // RTN13 - context("Ping") { // RTN13a it("should send a ProtocolMessage with action HEARTBEAT and expects a HEARTBEAT message in response") { @@ -1322,32 +1329,6 @@ class RealtimeClientConnection: QuickSpec { } - // RTN13 - context("Ping") { - - // RTN13b - pending("should immediately indicate an error if in the CLOSED or FAILED state") { - let client = AblyTests.newRealtime(AblyTests.commonAppSetup()) - defer { client.close() } - waitUntil(timeout: testTimeout) { done in - client.connection.on(.Connected) { _ in - client.onError(AblyTests.newErrorProtocolMessage()) - done() - } - } - waitUntil(timeout: testTimeout) { done in - client.ping() { error in - expect(error).toNot(beNil()) - let transport = client.transport as! TestProxyTransport - expect(transport.protocolMessagesSent.filter{ $0.action == .Heartbeat }).to(haveCount(1)) - expect(transport.protocolMessagesReceived.filter{ $0.action == .Heartbeat }).to(haveCount(0)) - done() - } - } - } - - } - // RTN14a it("should enter FAILED state when API key is invalid") { let options = AblyTests.commonAppSetup()