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 9c31643 commit 5c07af8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
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 5c07af8

Please sign in to comment.