diff --git a/ios/PacketTunnelCore/Actor/State.swift b/ios/PacketTunnelCore/Actor/State.swift index 4449372762d6..c445335d1771 100644 --- a/ios/PacketTunnelCore/Actor/State.swift +++ b/ios/PacketTunnelCore/Actor/State.swift @@ -193,7 +193,7 @@ public enum BlockedStateReason: String, Codable, Equatable { case tunnelAdapter /// Invalid public key. - case invalidPublicKey + case invalidRelayPublicKey /// Unidentified reason. case unknown diff --git a/ios/PacketTunnelCoreTests/Mocks/DefaultPathObserverFake.swift b/ios/PacketTunnelCoreTests/Mocks/DefaultPathObserverFake.swift index b237647b30f0..8c85855deb6e 100644 --- a/ios/PacketTunnelCoreTests/Mocks/DefaultPathObserverFake.swift +++ b/ios/PacketTunnelCoreTests/Mocks/DefaultPathObserverFake.swift @@ -22,19 +22,23 @@ class DefaultPathObserverFake: DefaultPathObserverProtocol { private var innerPath: NetworkPath = NetworkPathStub() private var stateLock = NSLock() + private var defaultPathHandler: ((NetworkPath) -> Void)? - var defaultPathHandler: ((NetworkPath) -> Void)? + public var onStart: (() -> Void)? + public var onStop: (() -> Void)? func start(_ body: @escaping (NetworkPath) -> Void) { stateLock.withLock { defaultPathHandler = body } + onStart?() } func stop() { stateLock.withLock { defaultPathHandler = nil } + onStop?() } /// Simulate network path update. diff --git a/ios/PacketTunnelCoreTests/PacketTunnelActorTests.swift b/ios/PacketTunnelCoreTests/PacketTunnelActorTests.swift index 2b4861d494bc..05346c4bbcf0 100644 --- a/ios/PacketTunnelCoreTests/PacketTunnelActorTests.swift +++ b/ios/PacketTunnelCoreTests/PacketTunnelActorTests.swift @@ -197,7 +197,11 @@ final class PacketTunnelActorTests: XCTestCase { func testStopCancelsDefaultPathObserver() async throws { let pathObserver = DefaultPathObserverFake() let actor = PacketTunnelActor.mock(defaultPathObserver: pathObserver) + let connectedStateExpectation = expectation(description: "Connected state") + let didStopObserverExpectation = expectation(description: "Did stop path observer") + didStopObserverExpectation.expectedFulfillmentCount = 2 + pathObserver.onStop = { didStopObserverExpectation.fulfill() } let expression: (State) -> Bool = { if case .connected = $0 { true } else { false } } @@ -214,9 +218,7 @@ final class PacketTunnelActorTests: XCTestCase { disconnectedStateExpectation.fulfill() } actor.stop() - await fulfillment(of: [disconnectedStateExpectation], timeout: 1) - - XCTAssertNil(pathObserver.defaultPathHandler) + await fulfillment(of: [disconnectedStateExpectation, didStopObserverExpectation], timeout: 1) } func testSetErrorStateGetsCancelled() async throws {