Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RTN13b #436

Merged
merged 3 commits into from
Apr 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Source/ARTRealtime.m
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
27 changes: 17 additions & 10 deletions Spec/RealtimeClientConnection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1263,7 +1263,7 @@ class RealtimeClientConnection: QuickSpec {
}
}

// RTN13b
// RTN13
context("ping") {
// RTN13b
it("fails if in the INITIALIZED, SUSPENDED, CLOSING, CLOSED or FAILED state") {
Expand All @@ -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") {
Expand Down