Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix test expectations not being waited on #437

Merged
merged 2 commits into from
Dec 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
}