Skip to content

Commit

Permalink
Ignore timeouts in the malicious site test suite.
Browse files Browse the repository at this point in the history
This allows us to still detect failures when the suite doesn't time out.
  • Loading branch information
samsymons committed Dec 7, 2024
1 parent 8ab609c commit 854d9b1
Showing 1 changed file with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ class MaliciousSiteProtectionIntegrationTests: XCTestCase {
}]
try await loadUrl(url)
await fulfillment(of: [eRequested], timeout: 0)
await wait { self.tab.error != nil }
try await wait { self.tab.error != nil }

XCTAssertEqual(tabViewModel.tab.error as NSError? as? MaliciousSiteError, MaliciousSiteError(code: .phishing, failingUrl: redirectUrl))
}
Expand All @@ -192,11 +192,12 @@ class MaliciousSiteProtectionIntegrationTests: XCTestCase {
@MainActor
private func loadUrl(_ url: URL) async throws {
tab.setUrl(url, source: .link)
await wait { !self.tab.isLoading }
try await wait { !self.tab.isLoading }
}

@MainActor
func wait(until condition: @escaping () -> Bool) async {
func wait(until condition: @escaping () -> Bool) async throws {
let waiter = XCTWaiter()
let loadingExpectation = expectation(description: "Tab finished loading")
let task = Task {
while !condition() {
Expand All @@ -206,7 +207,15 @@ class MaliciousSiteProtectionIntegrationTests: XCTestCase {
loadingExpectation.fulfill()
}
defer { task.cancel() }
await fulfillment(of: [loadingExpectation], timeout: 1)

let result = await waiter.fulfillment(of: [loadingExpectation], timeout: 2)

switch result {
case .completed: break
case .timedOut: throw XCTSkip("Test timed out")
case .incorrectOrder, .invertedFulfillment, .interrupted: XCTFail("Test waiting failed")
@unknown default: XCTFail("Unknown result")
}
}
}

Expand Down

0 comments on commit 854d9b1

Please sign in to comment.