From 912a8151a4fc3f8879ec3262a766077a6ffb2817 Mon Sep 17 00:00:00 2001 From: Marat Al Date: Sun, 20 Feb 2022 22:44:09 +0100 Subject: [PATCH 1/4] Moved fallbackRetryTimeout from ARTDefault to ARTClientOption --- Source/ARTClientOptions.h | 5 +++++ Source/ARTClientOptions.m | 3 ++- Source/ARTDefault+Private.h | 1 - Source/ARTDefault.h | 5 ----- Source/ARTDefault.m | 11 ----------- Source/ARTRest.m | 2 +- 6 files changed, 8 insertions(+), 19 deletions(-) diff --git a/Source/ARTClientOptions.h b/Source/ARTClientOptions.h index 0365bb7cc..493c639f4 100644 --- a/Source/ARTClientOptions.h +++ b/Source/ARTClientOptions.h @@ -67,6 +67,11 @@ NS_ASSUME_NONNULL_BEGIN */ @property (readwrite, assign, nonatomic) NSTimeInterval httpRequestTimeout; +/** + The period in seconds before HTTP requests are retried against the default endpoint + */ +@property (readwrite, assign, nonatomic) NSTimeInterval fallbackRetryTimeout; + /** Max number of fallback host retries for HTTP requests that fail due to network issues or server problems. */ diff --git a/Source/ARTClientOptions.m b/Source/ARTClientOptions.m index 6746987ef..f7f0b093e 100644 --- a/Source/ARTClientOptions.m +++ b/Source/ARTClientOptions.m @@ -37,6 +37,7 @@ - (instancetype)initDefaults { _channelRetryTimeout = 15.0; //Seconds _httpOpenTimeout = 4.0; //Seconds _httpRequestTimeout = 10.0; //Seconds + _fallbackRetryTimeout = 600.0; // Seconds, TO3l10 _httpMaxRetryDuration = 15.0; //Seconds _httpMaxRetryCount = 3; _fallbackHosts = nil; @@ -120,7 +121,7 @@ - (id)copyWithZone:(NSZone *)zone { options.httpMaxRetryCount = self.httpMaxRetryCount; options.httpMaxRetryDuration = self.httpMaxRetryDuration; options.httpOpenTimeout = self.httpOpenTimeout; - options.httpRequestTimeout = self.httpRequestTimeout; + options.fallbackRetryTimeout = self.fallbackRetryTimeout; options->_fallbackHosts = self.fallbackHosts; //ignore setter #pragma clang diagnostic push diff --git a/Source/ARTDefault+Private.h b/Source/ARTDefault+Private.h index b5aeb3946..1b1a0dd22 100644 --- a/Source/ARTDefault+Private.h +++ b/Source/ARTDefault+Private.h @@ -9,6 +9,5 @@ extern NSString *const ARTDefault_variant; + (void)setRealtimeRequestTimeout:(NSTimeInterval)value; + (void)setConnectionStateTtl:(NSTimeInterval)value; + (void)setMaxMessageSize:(NSInteger)value; -+ (void)setFallbackRetryTimeout:(NSTimeInterval)value; @end diff --git a/Source/ARTDefault.h b/Source/ARTDefault.h index 5fd26ca9a..7a98717d5 100644 --- a/Source/ARTDefault.h +++ b/Source/ARTDefault.h @@ -37,11 +37,6 @@ NS_ASSUME_NONNULL_BEGIN + (NSInteger)maxMessageSize; -/** - The period in seconds before HTTP requests are retried against the default endpoint - */ -+ (NSTimeInterval)fallbackRetryTimeout; - @end NS_ASSUME_NONNULL_END diff --git a/Source/ARTDefault.m b/Source/ARTDefault.m index c94d72b12..49775c2ec 100644 --- a/Source/ARTDefault.m +++ b/Source/ARTDefault.m @@ -35,7 +35,6 @@ static inline UInt32 conformVersionComponent(const NSInteger component) { ; static NSTimeInterval _realtimeRequestTimeout = 10.0; -static NSTimeInterval _fallbackRetryTimeout = 600.0; // TO3l10 static NSTimeInterval _connectionStateTtl = 60.0; static NSInteger _maxMessageSize = 65536; @@ -87,10 +86,6 @@ + (NSTimeInterval)ttl { return 60 * 60; } -+ (NSTimeInterval)fallbackRetryTimeout { - return _fallbackRetryTimeout; -} - + (NSTimeInterval)connectionStateTtl { return _connectionStateTtl; } @@ -121,12 +116,6 @@ + (void)setMaxMessageSize:(NSInteger)value { } } -+ (void)setFallbackRetryTimeout:(NSTimeInterval)value { - @synchronized (self) { - _fallbackRetryTimeout = value; - } -} - + (NSString *)bundleVersion { NSDictionary *infoDictionary = [[NSBundle bundleForClass: [ARTDefault class]] infoDictionary]; return infoDictionary[ARTDefault_bundleVersionKey]; diff --git a/Source/ARTRest.m b/Source/ARTRest.m index c5d2042a1..8a2e889aa 100644 --- a/Source/ARTRest.m +++ b/Source/ARTRest.m @@ -712,7 +712,7 @@ - (void)setCurrentFallbackHost:(NSString *)value { _currentFallbackHost = value; - _fallbackRetryExpiration = [ARTTime timeSinceBoot] + [ARTDefault fallbackRetryTimeout]; + _fallbackRetryExpiration = [ARTTime timeSinceBoot] + _options.fallbackRetryTimeout; } #if TARGET_OS_IOS From 4498934b94c81364128f1ed68e5b9e841ac24609 Mon Sep 17 00:00:00 2001 From: Marat Al Date: Sun, 20 Feb 2022 22:44:24 +0100 Subject: [PATCH 2/4] Tests updated for fallbackRetryTimeout --- Spec/Tests/RestClientTests.swift | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/Spec/Tests/RestClientTests.swift b/Spec/Tests/RestClientTests.swift index dbde357d9..7f4a76d94 100644 --- a/Spec/Tests/RestClientTests.swift +++ b/Spec/Tests/RestClientTests.swift @@ -80,6 +80,7 @@ private func testStoresSuccessfulFallbackHostAsDefaultHost(_ caseTest: FakeNetwo private func testRestoresDefaultPrimaryHostAfterTimeoutExpires(_ caseTest: FakeNetworkResponse) { let options = ARTClientOptions(key: "xxxx:xxxx") options.logLevel = .debug + options.fallbackRetryTimeout = 1 let client = ARTRest(options: options) let mockHTTP = MockHTTP(logger: options.logHandler) testHTTPExecutor = TestProxyHTTPExecutor(http: mockHTTP, logger: options.logHandler) @@ -107,6 +108,7 @@ private func testRestoresDefaultPrimaryHostAfterTimeoutExpires(_ caseTest: FakeN private func testUsesAnotherFallbackHost(_ caseTest: FakeNetworkResponse) { let options = ARTClientOptions(key: "xxxx:xxxx") + options.fallbackRetryTimeout = 10 options.logLevel = .debug let client = ARTRest(options: options) let mockHTTP = MockHTTP(logger: options.logHandler) @@ -1185,6 +1187,7 @@ class RestClientTests: XCTestCase { func test__049__RestClient__Host_Fallback__every_new_HTTP_request_is_first_attempted_to_the_default_primary_host_rest_ably_io() { let options = ARTClientOptions(key: "xxxx:xxxx") options.httpMaxRetryCount = 1 + options.fallbackRetryTimeout = 1 // RSC15j exception let client = ARTRest(options: options) let mockHTTP = MockHTTP(logger: options.logHandler) testHTTPExecutor = TestProxyHTTPExecutor(http: mockHTTP, logger: options.logHandler) @@ -1192,9 +1195,6 @@ class RestClientTests: XCTestCase { mockHTTP.setNetworkState(network: .hostUnreachable, resetAfter: 1) let channel = client.channels.get("test") - // RSC15j exception - ARTDefault.setFallbackRetryTimeout(1) - waitUntil(timeout: testTimeout) { done in channel.publish(nil, data: "nil") { _ in done() @@ -1533,46 +1533,32 @@ class RestClientTests: XCTestCase { testStoresSuccessfulFallbackHostAsDefaultHost(.hostInternalError(code: 501)) } - func beforeEach__RestClient__Host_Fallback__should_store_successful_fallback_host_as_default_host__should_restore_default_primary_host_after_fallbackRetryTimeout_expired() { - ARTDefault.setFallbackRetryTimeout(1.0) - } - func test__080__RestClient__Host_Fallback__should_store_successful_fallback_host_as_default_host__should_restore_default_primary_host_after_fallbackRetryTimeout_expired___hostUnreachable() { - beforeEach__RestClient__Host_Fallback__should_store_successful_fallback_host_as_default_host__should_restore_default_primary_host_after_fallbackRetryTimeout_expired() - + testRestoresDefaultPrimaryHostAfterTimeoutExpires(.hostUnreachable) } func test__081__RestClient__Host_Fallback__should_store_successful_fallback_host_as_default_host__should_restore_default_primary_host_after_fallbackRetryTimeout_expired___requestTimeout_timeout__0_1_() { - beforeEach__RestClient__Host_Fallback__should_store_successful_fallback_host_as_default_host__should_restore_default_primary_host_after_fallbackRetryTimeout_expired() testRestoresDefaultPrimaryHostAfterTimeoutExpires(.requestTimeout(timeout: 0.1)) } func test__082__RestClient__Host_Fallback__should_store_successful_fallback_host_as_default_host__should_restore_default_primary_host_after_fallbackRetryTimeout_expired___hostInternalError_code__501_() { - beforeEach__RestClient__Host_Fallback__should_store_successful_fallback_host_as_default_host__should_restore_default_primary_host_after_fallbackRetryTimeout_expired() testRestoresDefaultPrimaryHostAfterTimeoutExpires(.hostInternalError(code: 501)) } - func beforeEach__RestClient__Host_Fallback__should_store_successful_fallback_host_as_default_host__should_use_another_fallback_host_if_previous_fallback_request_failed_and_store_it_as_default_if_current_fallback_request_succseeded() { - ARTDefault.setFallbackRetryTimeout(10) - } - func test__083__RestClient__Host_Fallback__should_store_successful_fallback_host_as_default_host__should_use_another_fallback_host_if_previous_fallback_request_failed_and_store_it_as_default_if_current_fallback_request_succseeded___hostUnreachable() { - beforeEach__RestClient__Host_Fallback__should_store_successful_fallback_host_as_default_host__should_use_another_fallback_host_if_previous_fallback_request_failed_and_store_it_as_default_if_current_fallback_request_succseeded() testUsesAnotherFallbackHost(.hostUnreachable) } func test__084__RestClient__Host_Fallback__should_store_successful_fallback_host_as_default_host__should_use_another_fallback_host_if_previous_fallback_request_failed_and_store_it_as_default_if_current_fallback_request_succseeded___requestTimeout_timeout__0_1_() { - beforeEach__RestClient__Host_Fallback__should_store_successful_fallback_host_as_default_host__should_use_another_fallback_host_if_previous_fallback_request_failed_and_store_it_as_default_if_current_fallback_request_succseeded() testUsesAnotherFallbackHost(.requestTimeout(timeout: 0.1)) } func test__085__RestClient__Host_Fallback__should_store_successful_fallback_host_as_default_host__should_use_another_fallback_host_if_previous_fallback_request_failed_and_store_it_as_default_if_current_fallback_request_succseeded___hostInternalError_code__501_() { - beforeEach__RestClient__Host_Fallback__should_store_successful_fallback_host_as_default_host__should_use_another_fallback_host_if_previous_fallback_request_failed_and_store_it_as_default_if_current_fallback_request_succseeded() testUsesAnotherFallbackHost(.hostInternalError(code: 501)) } From 82868c34c35070fe4c2ff8881255e4a3703d2f4e Mon Sep 17 00:00:00 2001 From: Marat Al Date: Sun, 6 Mar 2022 19:17:44 +0100 Subject: [PATCH 3/4] Removed unwanted empty lines --- Spec/Tests/RestClientTests.swift | 6 ------ 1 file changed, 6 deletions(-) diff --git a/Spec/Tests/RestClientTests.swift b/Spec/Tests/RestClientTests.swift index 7f4a76d94..f4a294a4a 100644 --- a/Spec/Tests/RestClientTests.swift +++ b/Spec/Tests/RestClientTests.swift @@ -1534,32 +1534,26 @@ class RestClientTests: XCTestCase { } func test__080__RestClient__Host_Fallback__should_store_successful_fallback_host_as_default_host__should_restore_default_primary_host_after_fallbackRetryTimeout_expired___hostUnreachable() { - testRestoresDefaultPrimaryHostAfterTimeoutExpires(.hostUnreachable) } func test__081__RestClient__Host_Fallback__should_store_successful_fallback_host_as_default_host__should_restore_default_primary_host_after_fallbackRetryTimeout_expired___requestTimeout_timeout__0_1_() { - testRestoresDefaultPrimaryHostAfterTimeoutExpires(.requestTimeout(timeout: 0.1)) } func test__082__RestClient__Host_Fallback__should_store_successful_fallback_host_as_default_host__should_restore_default_primary_host_after_fallbackRetryTimeout_expired___hostInternalError_code__501_() { - testRestoresDefaultPrimaryHostAfterTimeoutExpires(.hostInternalError(code: 501)) } func test__083__RestClient__Host_Fallback__should_store_successful_fallback_host_as_default_host__should_use_another_fallback_host_if_previous_fallback_request_failed_and_store_it_as_default_if_current_fallback_request_succseeded___hostUnreachable() { - testUsesAnotherFallbackHost(.hostUnreachable) } func test__084__RestClient__Host_Fallback__should_store_successful_fallback_host_as_default_host__should_use_another_fallback_host_if_previous_fallback_request_failed_and_store_it_as_default_if_current_fallback_request_succseeded___requestTimeout_timeout__0_1_() { - testUsesAnotherFallbackHost(.requestTimeout(timeout: 0.1)) } func test__085__RestClient__Host_Fallback__should_store_successful_fallback_host_as_default_host__should_use_another_fallback_host_if_previous_fallback_request_failed_and_store_it_as_default_if_current_fallback_request_succseeded___hostInternalError_code__501_() { - testUsesAnotherFallbackHost(.hostInternalError(code: 501)) } From b9b426b69c6e0d5741e235a083284ede6fbaa964 Mon Sep 17 00:00:00 2001 From: Marat Al Date: Sun, 6 Mar 2022 19:31:22 +0100 Subject: [PATCH 4/4] Doc comment for `fallbackRetryTimeout` property updated --- Source/ARTClientOptions.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Source/ARTClientOptions.h b/Source/ARTClientOptions.h index 493c639f4..78f5eaa08 100644 --- a/Source/ARTClientOptions.h +++ b/Source/ARTClientOptions.h @@ -68,7 +68,8 @@ NS_ASSUME_NONNULL_BEGIN @property (readwrite, assign, nonatomic) NSTimeInterval httpRequestTimeout; /** - The period in seconds before HTTP requests are retried against the default endpoint + The period in seconds before HTTP requests are retried against the default endpoint. + (After a failed request to the default endpoint, followed by a successful request to a fallback endpoint) */ @property (readwrite, assign, nonatomic) NSTimeInterval fallbackRetryTimeout;