From 6fa4ba1616953842b109134994117e0e39085e71 Mon Sep 17 00:00:00 2001 From: Jim Boulter Date: Mon, 9 Dec 2024 16:12:15 -0800 Subject: [PATCH 1/2] Fix test expectations not being waited on --- .../GlobalErrorResponseHandlerTests.swift | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Source/SwiftyDropboxUnitTests/GlobalErrorResponseHandlerTests.swift b/Source/SwiftyDropboxUnitTests/GlobalErrorResponseHandlerTests.swift index 5b74017d..d093d62e 100644 --- a/Source/SwiftyDropboxUnitTests/GlobalErrorResponseHandlerTests.swift +++ b/Source/SwiftyDropboxUnitTests/GlobalErrorResponseHandlerTests.swift @@ -29,6 +29,7 @@ class GlobalErrorResponseHandlerTests: XCTestCase { expectation.fulfill() } handler.reportGlobalError(error.typeErased) + wait(for: [expectation], timeout: 1) } func testGlobalHandlerReportsRouteError() { @@ -46,6 +47,7 @@ class GlobalErrorResponseHandlerTests: XCTestCase { expectation.fulfill() } handler.reportGlobalError(error.typeErased) + wait(for: [expectation], timeout: 1) } func testDeregisterGlobalHandler() { @@ -58,15 +60,21 @@ class GlobalErrorResponseHandlerTests: XCTestCase { } 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.authError(Auth.AuthError.expiredAccessToken, LocalizedUserMessage(text: "ábc", locale: "EN-US"), "abc", "def") handler.reportGlobalError(error.typeErased) + + wait(for: [expectation], timeout: 1) } } @@ -135,6 +143,7 @@ class RequestGlobalErrorHandlerIntegrationTests: XCTestCase { } handler.deregisterGlobalErrorHandler(key: key) + wait(for: [globalExpectation, completionHandlerExpectation], timeout: 1) } func testDownloadRequestGlobalErrorHandler() { @@ -165,6 +174,7 @@ class RequestGlobalErrorHandlerIntegrationTests: XCTestCase { } handler.deregisterGlobalErrorHandler(key: key) + wait(for: [globalExpectation, completionHandlerExpectation], timeout: 1) } func testUploadRequestGlobalErrorHandler() { @@ -199,5 +209,6 @@ class RequestGlobalErrorHandlerIntegrationTests: XCTestCase { } handler.deregisterGlobalErrorHandler(key: key) + wait(for: [globalExpectation, completionHandlerExpectation], timeout: 1) } } From 7de89f01d86d93f857430b92500cf6076d0d3c7d Mon Sep 17 00:00:00 2001 From: Jim Boulter Date: Mon, 9 Dec 2024 16:14:32 -0800 Subject: [PATCH 2/2] Missed one --- .../GlobalErrorResponseHandlerTests.swift | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Source/SwiftyDropboxUnitTests/GlobalErrorResponseHandlerTests.swift b/Source/SwiftyDropboxUnitTests/GlobalErrorResponseHandlerTests.swift index d093d62e..79484674 100644 --- a/Source/SwiftyDropboxUnitTests/GlobalErrorResponseHandlerTests.swift +++ b/Source/SwiftyDropboxUnitTests/GlobalErrorResponseHandlerTests.swift @@ -51,12 +51,17 @@ class GlobalErrorResponseHandlerTests: XCTestCase { } 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.authError(Auth.AuthError.expiredAccessToken, LocalizedUserMessage(text: "ábc", locale: "EN-US"), "abc", "def") handler.reportGlobalError(error.typeErased) + + wait(for: [expectation], timeout: 1) } func testDeregisterAllGlobalHandlers() {