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

RTN17c #388

Merged
merged 3 commits into from
May 5, 2016
Merged
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
56 changes: 56 additions & 0 deletions Spec/RealtimeClientConnection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2529,6 +2529,62 @@ class RealtimeClientConnection: QuickSpec {
expect(NSRegularExpression.match(urlConnections[2].absoluteString, pattern: "//realtime.ably.io")).to(beTrue())
}

// RTN17c
pending("should retry hosts in random order after checkin if an internet connection is available") {
let expectedHostOrder = [4, 3, 0, 2, 1]

let originalARTFallback_getRandomHostIndex = ARTFallback_getRandomHostIndex
ARTFallback_getRandomHostIndex = {
let hostIndexes = [1, 1, 0, 0, 0]
var i = 0
return { count in
let hostIndex = hostIndexes[i]
i += 1
return Int32(hostIndex)
}
}()
defer {
ARTFallback_getRandomHostIndex = originalARTFallback_getRandomHostIndex
}

let options = ARTClientOptions(key: "xxxx:xxxx")
options.autoConnect = false
let client = ARTRealtime(options: options)
let channel = client.channels.get("test")

let testHttpExecutor = TestProxyHTTPExecutor()
client.rest.httpExecutor = testHttpExecutor

client.setTransportClass(TestProxyTransport.self)
TestProxyTransport.network = .HostUnreachable
defer { TestProxyTransport.network = nil }

var urlConnections = [NSURL]()
TestProxyTransport.networkConnectEvent = { url in
urlConnections.append(url)
}

client.connect()
defer { client.close() }

waitUntil(timeout: testTimeout) { done in
channel.publish(nil, data: "message") { error in
done()
}
}

expect(NSRegularExpression.match(testHttpExecutor.requests[0].URL!.absoluteString, pattern: "//internet-up.ably-realtime.com/is-the-internet-up.txt")).to(beTrue())
expect(urlConnections).to(haveCount(6)) // default + 5 fallbacks

let extractHostname = { (url: NSURL) in
NSRegularExpression.extract(url.absoluteString, pattern: "[a-e].ably-realtime.com")
}
let resultFallbackHosts = urlConnections.flatMap(extractHostname)
let expectedFallbackHosts = Array(expectedHostOrder.map({ ARTDefault.fallbackHosts()[$0] as! String }))

expect(resultFallbackHosts).to(equal(expectedFallbackHosts))
}

}

// RTN18
Expand Down