From 122a2182d8d8cc4048226cda0c9a9d6fd7a07b45 Mon Sep 17 00:00:00 2001 From: Evgeny Karkan Date: Wed, 21 Sep 2016 18:04:22 +0300 Subject: [PATCH] RTN17b as a part of 0.9 (#502) --- Source/ARTRealtime.m | 2 +- Spec/RealtimeClientConnection.swift | 35 +++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/Source/ARTRealtime.m b/Source/ARTRealtime.m index 7c534d677..6bc4b77b6 100644 --- a/Source/ARTRealtime.m +++ b/Source/ARTRealtime.m @@ -777,7 +777,7 @@ - (void)realtimeTransportFailed:(id)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; diff --git a/Spec/RealtimeClientConnection.swift b/Spec/RealtimeClientConnection.swift index af9e08296..844b5a5fd 100644 --- a/Spec/RealtimeClientConnection.swift +++ b/Spec/RealtimeClientConnection.swift @@ -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") {