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

RTN17b as a part of 0.9 #502

Merged
merged 1 commit into from
Sep 21, 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 @@ -777,7 +777,7 @@ - (void)realtimeTransportFailed:(id<ARTRealtimeTransport>)transport withError:(A
[self.logger debug:__FILE__ line:__LINE__ message:@"R:%p host is down; can retry with fallback host", self];
if (!_fallbacks && [error.url.host isEqualToString:[ARTDefault realtimeHost]]) {
[self.rest internetIsUp:^void(BOOL isUp) {
_fallbacks = [[ARTFallback alloc] init];
_fallbacks = [[ARTFallback alloc] initWithFallbackHosts:[self getClientOptions].fallbackHosts];
[self reconnectWithFallback];
}];
return;
Expand Down
35 changes: 35 additions & 0 deletions Spec/RealtimeClientConnection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2528,6 +2528,41 @@ class RealtimeClientConnection: QuickSpec {
expect(NSRegularExpression.match(urlConnections[0].absoluteString, pattern: "//realtime.ably.io")).to(beTrue())
expect(NSRegularExpression.match(urlConnections[1].absoluteString, pattern: "//[a-e].ably-realtime.com")).to(beTrue())
}

it("applies when an array of ClientOptions#fallbackHosts is provided") {
let options = ARTClientOptions(key: "xxxx:xxxx")
options.autoConnect = false
options.fallbackHosts = ["f.ably-realtime.com", "g.ably-realtime.com", "h.ably-realtime.com", "i.ably-realtime.com", "j.ably-realtime.com"]
let client = ARTRealtime(options: options)
let channel = client.channels.get("test")

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

var urlConnections = [NSURL]()
TestProxyTransport.networkConnectEvent = { url in
urlConnections.append(url)
if urlConnections.count == 1 {
TestProxyTransport.network = nil
}
}

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

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

expect(urlConnections.count > 1 && urlConnections.count <= options.fallbackHosts!.count + 1).to(beTrue())
expect(NSRegularExpression.match(urlConnections[0].absoluteString, pattern: "//realtime.ably.io")).to(beTrue())
for connection in urlConnections.dropFirst() {
expect(NSRegularExpression.match(connection.absoluteString, pattern: "//[f-j].ably-realtime.com")).to(beTrue())
}
}

// RTN17d
context("should use an alternative host when") {
Expand Down