Skip to content

Commit

Permalink
fix test hanging
Browse files Browse the repository at this point in the history
  • Loading branch information
nuo-xu committed Jan 7, 2025
1 parent b375744 commit d057915
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions ios/brave-ios/Tests/BrowserMenuTests/BrowserMenuTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class BrowserMenuTests: XCTestCase {
key: "visibilities",
default: [:]
)
private var cancellables: Set<AnyCancellable> = .init()

override func tearDown() {
super.tearDown()
Expand Down Expand Up @@ -297,7 +298,7 @@ class BrowserMenuTests: XCTestCase {
XCTAssertEqual(model.visibleActions, Array(actions[0..<3]))
}

@MainActor func testVPNRegionPublishing() async throws {
@MainActor func testVPNRegionPublishing() {
let vpnStatusPublisher = CurrentValueSubject<VPNStatus, Never>(.disconnected)
let model = BrowserMenuModel(
actions: [],
Expand All @@ -306,20 +307,21 @@ class BrowserMenuTests: XCTestCase {
actionRanks: actionRanks
)
XCTAssertEqual(model.vpnStatus, .disconnected)
// CurrentValueSubject vends its current value immediately to the stream so we want to ignore
// it as we already asserted the state of that before
model.$vpnStatus
.dropFirst()
.sink { vpnStatus in
switch vpnStatus {
case .connected(let region):
XCTAssertEqual(region.flag, "🇨🇦")
XCTAssertEqual(region.displayName, "ca-east")
case .disconnected:
XCTFail("VPN Region is wrong")
}
}.store(in: &cancellables)
vpnStatusPublisher.send(
.connected(activeRegion: .init(countryCode: "CA", displayName: "ca-east"))
)
// CurrentValueSubject vends its current value immediately to the stream so we want to ignore
// it as we already asserted the state of that before
for await _ in model.$vpnStatus.values.dropFirst() {
switch model.vpnStatus {
case .connected(let region):
XCTAssertEqual(region.flag, "🇨🇦")
XCTAssertEqual(region.displayName, "ca-east")
case .disconnected:
XCTFail()
}
break
}
}
}

0 comments on commit d057915

Please sign in to comment.