Skip to content

Commit

Permalink
Merge pull request #221 from ably/fix-rtl3a
Browse files Browse the repository at this point in the history
Fix RTL3a.
  • Loading branch information
tcard committed Feb 18, 2016
2 parents dcd12b2 + 44868e3 commit c96bc45
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 14 deletions.
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

0 comments on commit c96bc45

Please sign in to comment.