Skip to content

Commit

Permalink
PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
buggmagnet authored and Jon Petersson committed Oct 11, 2023
1 parent 8e2a40f commit 7a43b0a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion ios/PacketTunnelCore/Actor/State.swift
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public enum BlockedStateReason: String, Codable, Equatable {
case tunnelAdapter

/// Invalid public key.
case invalidPublicKey
case invalidRelayPublicKey

/// Unidentified reason.
case unknown
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 5 additions & 3 deletions ios/PacketTunnelCoreTests/PacketTunnelActorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 } }

Expand All @@ -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 {
Expand Down

0 comments on commit 7a43b0a

Please sign in to comment.