Skip to content

Commit

Permalink
Fix test expectations not being waited on (#437)
Browse files Browse the repository at this point in the history
* Fix test expectations not being waited on

---------

Co-authored-by: Jim Boulter <jboulter@dropbox.com>
  • Loading branch information
jboulter11 and Jim Boulter authored Dec 10, 2024
1 parent 5221b64 commit d5b24fb
Showing 1 changed file with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class GlobalErrorResponseHandlerTests: XCTestCase {
expectation.fulfill()
}
handler.reportGlobalError(error.typeErased)
wait(for: [expectation], timeout: 1)
}

func testGlobalHandlerReportsRouteError() {
Expand All @@ -46,27 +47,39 @@ class GlobalErrorResponseHandlerTests: XCTestCase {
expectation.fulfill()
}
handler.reportGlobalError(error.typeErased)
wait(for: [expectation], timeout: 1)
}

func testDeregisterGlobalHandler() {
let expectation = XCTestExpectation(description: "Callback is called")
expectation.isInverted = true
let key = handler.registerGlobalErrorHandler { error in
expectation.fulfill()
XCTFail("Should not be called")
}
handler.deregisterGlobalErrorHandler(key: key)
let error = CallError<String>.authError(Auth.AuthError.expiredAccessToken, LocalizedUserMessage(text: "ábc", locale: "EN-US"), "abc", "def")
handler.reportGlobalError(error.typeErased)

wait(for: [expectation], timeout: 1)
}

func testDeregisterAllGlobalHandlers() {
let expectation = XCTestExpectation(description: "Callback is called")
expectation.isInverted = true
_ = handler.registerGlobalErrorHandler { error in
expectation.fulfill()
XCTFail("Should not be called")
}
_ = handler.registerGlobalErrorHandler { error in
expectation.fulfill()
XCTFail("Should not be called")
}
handler.deregisterAllGlobalErrorHandlers()
let error = CallError<String>.authError(Auth.AuthError.expiredAccessToken, LocalizedUserMessage(text: "ábc", locale: "EN-US"), "abc", "def")
handler.reportGlobalError(error.typeErased)

wait(for: [expectation], timeout: 1)
}
}

Expand Down Expand Up @@ -135,6 +148,7 @@ class RequestGlobalErrorHandlerIntegrationTests: XCTestCase {
}

handler.deregisterGlobalErrorHandler(key: key)
wait(for: [globalExpectation, completionHandlerExpectation], timeout: 1)
}

func testDownloadRequestGlobalErrorHandler() {
Expand Down Expand Up @@ -165,6 +179,7 @@ class RequestGlobalErrorHandlerIntegrationTests: XCTestCase {
}

handler.deregisterGlobalErrorHandler(key: key)
wait(for: [globalExpectation, completionHandlerExpectation], timeout: 1)
}

func testUploadRequestGlobalErrorHandler() {
Expand Down Expand Up @@ -199,5 +214,6 @@ class RequestGlobalErrorHandlerIntegrationTests: XCTestCase {
}

handler.deregisterGlobalErrorHandler(key: key)
wait(for: [globalExpectation, completionHandlerExpectation], timeout: 1)
}
}

0 comments on commit d5b24fb

Please sign in to comment.