Skip to content

Commit

Permalink
Added test for RTN20c
Browse files Browse the repository at this point in the history
  • Loading branch information
maratal committed May 2, 2023
1 parent 40303c0 commit 29fb344
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Source/ARTRealtime.m
Original file line number Diff line number Diff line change
Expand Up @@ -1049,6 +1049,10 @@ - (BOOL)isTokenError:(nullable ARTErrorInfo *)error {

- (void)transportReconnectWithExistingParameters {
[self resetTransportWithResumeKey:_transport.resumeKey connectionSerial:_transport.connectionSerial];
NSString *host = [self getClientOptions].testOptions.reconnectionRealtimeHost; // for tests purposes only, always `nil` in production
if (host != nil) {
[self.transport setHost:host];
}
[self transportConnectForcingNewToken:false newConnection:true];
}

Expand Down
1 change: 1 addition & 0 deletions Source/ARTTestClientOptions.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ - (nonnull id)copyWithZone:(nullable NSZone *)zone {
copied.realtimeRequestTimeout = self.realtimeRequestTimeout;
copied.shuffleArray = self.shuffleArray;
copied.transportFactory = self.transportFactory;
copied.reconnectionRealtimeHost = self.reconnectionRealtimeHost;

return copied;
}
Expand Down
5 changes: 5 additions & 0 deletions Source/PrivateHeaders/Ably/ARTTestClientOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ NS_ASSUME_NONNULL_BEGIN
*/
@property (nonatomic) id<ARTRealtimeTransportFactory> transportFactory;

/**
Initial value is `nil`.
*/
@property (readwrite, nonatomic) NSString *reconnectionRealtimeHost;

@end

NS_ASSUME_NONNULL_END
33 changes: 33 additions & 0 deletions Test/Tests/RealtimeClientConnectionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4137,6 +4137,39 @@ class RealtimeClientConnectionTests: XCTestCase {
client.connect()
}
}

// RTN20c
func test__106_b__Connection__Operating_System_events_for_network_internet_connectivity_changes__should_restart_the_pending_connection_attempt_if_the_operating_system_indicates_that_the_underlying_internet_connection_is_now_available_when_CONNECTING() {
let options = AblyTests.commonAppSetup()
let realtimeHost = options.realtimeHost
options.realtimeHost = "10.255.255.1" // non-routable IP address
options.autoConnect = false
options.testOptions.reconnectionRealtimeHost = realtimeHost
let client = ARTRealtime(options: options)
client.internal.setReachabilityClass(TestReachability.self)
defer { client.dispose(); client.close() }

waitUntil(timeout: testTimeout) { done in
client.connection.on { stateChange in
switch stateChange.current {
case .connecting:
guard let reachability = client.internal.reachability as? TestReachability else {
XCTFail("expected test reachability"); return
}
delay(0.2) { // delay more than `_reachabilityReconnectionAttemptThreshold` constant (0.1)
reachability.simulate(true)
}
case .connected:
done()
case .disconnected, .suspended:
XCTFail("Should never reach these states in this test.")
default:
break
}
}
client.connect()
}
}

// RTN22
func test__107__Connection__Operating_System_events_for_network_internet_connectivity_changes__Ably_can_request_that_a_connected_client_re_authenticates_by_sending_the_client_an_AUTH_ProtocolMessage() {
Expand Down

0 comments on commit 29fb344

Please sign in to comment.