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

RTN19a #343

Merged
merged 3 commits into from
Apr 5, 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
14 changes: 14 additions & 0 deletions Source/ARTRealtime.m
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,20 @@ - (void)transition:(ARTRealtimeConnectionState)state withErrorInfo:(ARTErrorInfo
_transport.delegate = self;
[_transport connect];
}

if (previousState == ARTRealtimeDisconnected) {
__GENERIC(NSArray, ARTQueuedMessage *) *pending = self.pendingMessages;
_pendingMessages = [[NSMutableArray alloc] init];
for (ARTQueuedMessage *queued in pending) {
[self send:queued.msg callback:^(ARTStatus *__art_nonnull status) {
for (id cb in queued.cbs) {
((void(^)(ARTStatus *__art_nonnull))cb)(status);
}
}];
}

}

break;
case ARTRealtimeConnected:
[self cancelSuspendTimer];
Expand Down
37 changes: 37 additions & 0 deletions Spec/RealtimeClientConnection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1701,6 +1701,43 @@ class RealtimeClientConnection: QuickSpec {
}
}

context("Transport disconnected side effects") {

// RTN19a
it("should resend any ProtocolMessage that is awaiting a ACK/NACK") {
let options = AblyTests.commonAppSetup()
options.logLevel = .Debug
options.disconnectedRetryTimeout = 0.1
let client = AblyTests.newRealtime(options)
defer { client.close() }
let channel = client.channels.get("test")
let transport = client.transport as! TestProxyTransport

expect(client.connection.state).toEventually(equal(ARTRealtimeConnectionState.Connected), timeout: testTimeout)

waitUntil(timeout: testTimeout) { done in
channel.attach { _ in done() }
}

waitUntil(timeout: testTimeout) { done in
transport.ignoreSends = true
channel.publish(nil, data: "message") { error in
expect(error).to(beNil())
let newTransport = client.transport as! TestProxyTransport
expect(transport.protocolMessagesReceived.filter{ $0.action == .Connected }).to(haveCount(1))
expect(newTransport.protocolMessagesReceived.filter{ $0.action == .Connected }).to(haveCount(1))
expect(transport.protocolMessagesSent.filter{ $0.action == .Message }).to(haveCount(0))
expect(transport.protocolMessagesSentIgnored.filter{ $0.action == .Message }).to(haveCount(1))
expect(newTransport.protocolMessagesSent.filter{ $0.action == .Message }).to(haveCount(1))
done()
}
transport.ignoreSends = false
client.onDisconnected()
}
}

}

}
}
}
6 changes: 6 additions & 0 deletions Spec/TestUtilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,7 @@ class TestProxyTransport: ARTWebSocketTransport {

private(set) var protocolMessagesSent = [ARTProtocolMessage]()
private(set) var protocolMessagesReceived = [ARTProtocolMessage]()
private(set) var protocolMessagesSentIgnored = [ARTProtocolMessage]()

private(set) var rawDataSent = [NSData]()
private(set) var rawDataReceived = [NSData]()
Expand All @@ -502,6 +503,7 @@ class TestProxyTransport: ARTWebSocketTransport {
var afterProcessingReceivedMessage: Optional<(ARTProtocolMessage)->()> = nil

var actionsIgnored = [ARTProtocolMessageAction]()
var ignoreSends = false

override func setupWebSocket(params: [NSURLQueryItem], withOptions options: ARTClientOptions, resumeKey: String?, connectionSerial: NSNumber?) -> NSURL {
let url = super.setupWebSocket(params, withOptions: options, resumeKey: resumeKey, connectionSerial: connectionSerial)
Expand All @@ -510,6 +512,10 @@ class TestProxyTransport: ARTWebSocketTransport {
}

override func send(msg: ARTProtocolMessage) {
if ignoreSends {
protocolMessagesSentIgnored.append(msg)
return
}
protocolMessagesSent.append(msg)
if let performEvent = beforeProcessingSentMessage {
performEvent(msg)
Expand Down