Skip to content

Commit

Permalink
Merge branch 'fix-testcannotreconnectafterstopping-flakiness-ios-391'
Browse files Browse the repository at this point in the history
  • Loading branch information
buggmagnet committed Nov 20, 2023
2 parents dee94d6 + 818e0b0 commit 20a9bfb
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions ios/PacketTunnelCoreTests/PacketTunnelActorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -358,20 +358,25 @@ final class PacketTunnelActorTests: XCTestCase {
func testCannotReconnectAfterStopping() async throws {
let actor = PacketTunnelActor.mock()

let disconnectedStateExpectation = expectation(description: "Expect disconnected state")

await expect(.disconnected, on: actor) { disconnectedStateExpectation.fulfill() }
let connectedStateExpectation = expectation(description: "Expect connected state")
let connectedState: (ObservedState) -> Bool = { if case .connected = $0 { true } else { false } }
await expect(connectedState, on: actor) {
connectedStateExpectation.fulfill()
}

actor.start(options: launchOptions)
actor.stop()
// Wait for the connected state to happen so it doesn't get coalesced immediately after the call to `actor.stop`
await fulfillment(of: [connectedStateExpectation], timeout: 1)

let disconnectedStateExpectation = expectation(description: "Expect disconnected state")
await expect(.disconnected, on: actor) { disconnectedStateExpectation.fulfill() }
actor.stop()
await fulfillment(of: [disconnectedStateExpectation], timeout: 1)

let reconnectingStateExpectation = expectation(description: "Expect initial state")
let reconnectingStateExpectation = expectation(description: "Expect reconnecting state")
reconnectingStateExpectation.isInverted = true
let expression: (ObservedState) -> Bool = { if case .reconnecting = $0 { true } else { false } }

await expect(expression, on: actor) { reconnectingStateExpectation.fulfill() }
let reconnectingState: (ObservedState) -> Bool = { if case .reconnecting = $0 { true } else { false } }
await expect(reconnectingState, on: actor) { reconnectingStateExpectation.fulfill() }

actor.reconnect(to: .random)
await fulfillment(
Expand Down

0 comments on commit 20a9bfb

Please sign in to comment.