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

Fix RTL3a. #221

Merged
merged 1 commit into from
Feb 18, 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
17 changes: 12 additions & 5 deletions ably-ios/ARTRealtime.m
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ - (void)transition:(ARTRealtimeConnectionState)state withErrorInfo:(ARTErrorInfo
ARTRealtimeConnectionState previousState = self.connection.state;
[self.connection setState:state];

ARTStatus *status = nil;

// On enter logic
switch (self.connection.state) {
case ARTRealtimeConnecting:
Expand Down Expand Up @@ -250,7 +252,8 @@ - (void)transition:(ARTRealtimeConnectionState)state withErrorInfo:(ARTErrorInfo
_transport = nil;
break;
case ARTRealtimeFailed:
[self.transport abort:[ARTStatus state:ARTStateConnectionFailed info:errorInfo]];
status = [ARTStatus state:ARTStateConnectionFailed info:errorInfo];
[self.transport abort:status];
self.transport.delegate = nil;
_transport = nil;
break;
Expand All @@ -272,7 +275,11 @@ - (void)transition:(ARTRealtimeConnectionState)state withErrorInfo:(ARTErrorInfo
if ([self shouldSendEvents]) {
[self sendQueuedMessages];
} else if (![self shouldQueueEvents]) {
[self failQueuedMessages:[self defaultError]];
[self failQueuedMessages:status];
ARTStatus *channelStatus = status;
if (!channelStatus) {
channelStatus = [self defaultError];
}
// For every Channel
for (ARTRealtimeChannel* channel in self.channels) {
if (channel.state == ARTRealtimeChannelInitialised || channel.state == ARTRealtimeChannelAttaching || channel.state == ARTRealtimeChannelAttached) {
Expand All @@ -283,14 +290,14 @@ - (void)transition:(ARTRealtimeConnectionState)state withErrorInfo:(ARTErrorInfo
[channel detachChannel:[ARTStatus state:ARTStateOk]];
}
else if(state == ARTRealtimeSuspended) {
[channel detachChannel:[self defaultError]];
[channel detachChannel:channelStatus];
}
else {
[channel setFailed:[self defaultError]];
[channel setFailed:channelStatus];
}
}
else {
[channel setSuspended:[self defaultError]];
[channel setSuspended:channelStatus];
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion ably-ios/ARTRealtimeChannel.m
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,8 @@ - (void)transition:(ARTRealtimeChannelState)state status:(ARTStatus *)status {
}

self.state = state;

_errorReason = status.errorInfo;

[self.statesEventEmitter emit:[NSNumber numberWithInt:state] with:status.errorInfo];
}

Expand Down
8 changes: 5 additions & 3 deletions ably-iosTests/ARTRealtimeAttachTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,11 @@ - (void) testAttachFailsOnFailedConnection {
}
}
else if(channel.state == ARTRealtimeChannelFailed) {
[channel attach];
XCTAssertNil(errorInfo);
[expectation fulfill];
XCTAssertNotNil(errorInfo);
[channel attach:^(ARTErrorInfo *errorInfo) {
XCTAssertNotNil(errorInfo);
[expectation fulfill];
}];
}
}];
[channel attach];
Expand Down
20 changes: 15 additions & 5 deletions ablySpec/RealtimeClientChannel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class RealtimeClientChannel: QuickSpec {
context("connection state") {

// RTL3a
pending("changes to FAILED") {
context("changes to FAILED") {

it("ATTACHING channel should transition to FAILED") {
let options = AblyTests.commonAppSetup()
Expand All @@ -100,13 +100,18 @@ class RealtimeClientChannel: QuickSpec {
expect(channel.state).to(equal(ARTRealtimeChannelState.Attaching))

waitUntil(timeout: testTimeout) { done in
let error = AblyTests.newErrorProtocolMessage()
channel.on { errorInfo in
if channel.state == .Failed {
expect(errorInfo!.code).to(equal(90000))
guard let errorInfo = errorInfo else {
fail("errorInfo is nil"); done(); return
}
expect(errorInfo).to(equal(error.error))
expect(channel.errorReason).to(equal(errorInfo))
done()
}
}
client.onError(AblyTests.newErrorProtocolMessage())
client.onError(error)
}
expect(channel.state).to(equal(ARTRealtimeChannelState.Failed))
}
Expand All @@ -120,13 +125,18 @@ class RealtimeClientChannel: QuickSpec {
expect(channel.state).toEventually(equal(ARTRealtimeChannelState.Attached), timeout: testTimeout)

waitUntil(timeout: testTimeout) { done in
let error = AblyTests.newErrorProtocolMessage()
channel.on { errorInfo in
if channel.state == .Failed {
expect(errorInfo!.code).to(equal(90000))
guard let errorInfo = errorInfo else {
fail("errorInfo is nil"); done(); return
}
expect(errorInfo).to(equal(error.error))
expect(channel.errorReason).to(equal(errorInfo))
done()
}
}
client.onError(AblyTests.newErrorProtocolMessage())
client.onError(error)
}
expect(channel.state).to(equal(ARTRealtimeChannelState.Failed))
}
Expand Down