diff options
| author | Andrej Mihajlov <and@mullvad.net> | 2023-08-17 13:39:11 +0200 |
|---|---|---|
| committer | Andrej Mihajlov <and@mullvad.net> | 2023-08-17 14:44:09 +0200 |
| commit | 181c710e554f3c2e4e4f80cde6f75b5080320507 (patch) | |
| tree | 9492002cc74d68f8097ac02204a12c63b25f57d5 | |
| parent | f0694bf653c8caf920e27715fa0821670cc67908 (diff) | |
| download | mullvadvpn-181c710e554f3c2e4e4f80cde6f75b5080320507.tar.xz mullvadvpn-181c710e554f3c2e4e4f80cde6f75b5080320507.zip | |
Log reconnection attempts
| -rw-r--r-- | ios/PacketTunnelCoreTests/TunnelMonitorTests.swift | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/ios/PacketTunnelCoreTests/TunnelMonitorTests.swift b/ios/PacketTunnelCoreTests/TunnelMonitorTests.swift index 462c2f1476..f5a9559a4a 100644 --- a/ios/PacketTunnelCoreTests/TunnelMonitorTests.swift +++ b/ios/PacketTunnelCoreTests/TunnelMonitorTests.swift @@ -68,6 +68,7 @@ final class TunnelMonitorTests: XCTestCase { capped at 15s max. */ var expectedTimings = [4, 8, 15, 15] + let totalAttemptCount = expectedTimings.count // Calculate the amount of time necessary to perform the test adding some leeway. let timeout = expectedTimings.reduce(1, +) @@ -78,16 +79,25 @@ final class TunnelMonitorTests: XCTestCase { // This date will be used to measure the amount of time elapsed between `.connectionLost` events. var startDate = Date() + // Reconnection attempt counter. + var currentAttempt = 0 + tunnelMonitor.onEvent = { [weak tunnelMonitor] event in guard case .connectionLost = event else { return } switch event { case .connectionLost: + XCTAssertFalse(expectedTimings.isEmpty) + let expectedDuration = expectedTimings.removeFirst() // Compute amount of time elapsed between `.connectionLost` events rounding it down towards zero. let timeElapsed = Int(Date().timeIntervalSince(startDate).rounded(.down)) + currentAttempt += 1 + + print("[\(currentAttempt)/\(totalAttemptCount)] \(event), time elapsed: \(timeElapsed)s") + XCTAssertEqual( timeElapsed, expectedDuration, @@ -96,9 +106,13 @@ final class TunnelMonitorTests: XCTestCase { expectation.fulfill() - if !expectedTimings.isEmpty { + if expectedTimings.isEmpty { + print("Finished.") + } else { startDate = Date() + print("Continue monitoring.") + // Continue monitoring by calling start() again. tunnelMonitor?.start(probeAddress: .loopback) } @@ -111,6 +125,8 @@ final class TunnelMonitorTests: XCTestCase { } } + print("Start monitoring.") + // Start monitoring. tunnelMonitor.start(probeAddress: .loopback) |
