diff options
Diffstat (limited to 'ios')
| -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) |
