Skip to content

Commit

Permalink
RTN17b as a part of 0.9 (#502)
Browse files Browse the repository at this point in the history
  • Loading branch information
EvgenyKarkan authored and tcard committed Sep 21, 2016
1 parent 90df98a commit 122a218
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
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

0 comments on commit 122a218

Please sign in to comment.