From 8891bdfe0b416ebf75aa683108c2a40857cc5ecb Mon Sep 17 00:00:00 2001 From: Dominik Kapusta Date: Tue, 24 Sep 2024 17:57:03 +0200 Subject: [PATCH] Fix ConfigurationManagerTests --- .../ConfigurationManagerTests.swift | 26 ++++++++----------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/Tests/ConfigurationTests/ConfigurationManagerTests.swift b/Tests/ConfigurationTests/ConfigurationManagerTests.swift index 97cd49569..4368a540d 100644 --- a/Tests/ConfigurationTests/ConfigurationManagerTests.swift +++ b/Tests/ConfigurationTests/ConfigurationManagerTests.swift @@ -132,16 +132,15 @@ final class ConfigurationManagerTests: XCTestCase { let managerA = makeConfigurationManager(name: "A") let managerB = makeConfigurationManager(name: "B") - var e: XCTestExpectation? = expectation(description: "ConfigManager B updated") + let e = expectation(description: "ConfigManager B updated") managerB.onDependenciesUpdated = { - e?.fulfill() - e = nil + e.fulfill() } let configData = Data("Privacy Config".utf8) MockURLProtocol.requestHandler = { _ in (HTTPURLResponse.ok, configData) } await managerA.refreshNow() - await fulfillment(of: [e!], timeout: 2) + await fulfillment(of: [e], timeout: 2) XCTAssertNotNil(MockURLProtocol.lastRequest) XCTAssertEqual(managerB.dependencyProvider.privacyConfigData, configData) @@ -152,16 +151,15 @@ final class ConfigurationManagerTests: XCTestCase { let managerA = makeConfigurationManager() let managerB = makeConfigurationManager() - var e: XCTestExpectation? = expectation(description: "ConfigManager B updated") + var e = expectation(description: "ConfigManager B updated") managerB.onDependenciesUpdated = { - e?.fulfill() - e = nil + e.fulfill() } var configData = Data("Privacy Config".utf8) MockURLProtocol.requestHandler = { _ in (HTTPURLResponse.ok, configData) } await managerA.refreshNow() - await fulfillment(of: [e!], timeout: 2) + await fulfillment(of: [e], timeout: 2) XCTAssertNotNil(MockURLProtocol.lastRequest) XCTAssertEqual(managerB.dependencyProvider.privacyConfigData, configData) @@ -171,14 +169,13 @@ final class ConfigurationManagerTests: XCTestCase { e = expectation(description: "ConfigManager A updated") managerB.onDependenciesUpdated = nil managerA.onDependenciesUpdated = { - e?.fulfill() - e = nil + e.fulfill() } configData = Data("Privacy Config 2".utf8) MockURLProtocol.requestHandler = { _ in (HTTPURLResponse.ok, configData) } await managerB.refreshNow() - await fulfillment(of: [e!], timeout: 2) + await fulfillment(of: [e], timeout: 2) XCTAssertNotNil(MockURLProtocol.lastRequest) XCTAssertEqual(managerA.dependencyProvider.privacyConfigData, configData) @@ -197,16 +194,15 @@ final class ConfigurationManagerTests: XCTestCase { let managerA = makeConfigurationManager() let managerB = makeConfigurationManager() - var e: XCTestExpectation? = expectation(description: "ConfigManager B updated") + let e = expectation(description: "ConfigManager B updated") managerB.onDependenciesUpdated = { - e?.fulfill() - e = nil + e.fulfill() } let configData = Data("Privacy Config".utf8) MockURLProtocol.requestHandler = { _ in (HTTPURLResponse.ok, configData) } await managerA.refreshNow() - await fulfillment(of: [e!], timeout: 2) + await fulfillment(of: [e], timeout: 2) XCTAssertNotNil(MockURLProtocol.lastRequest) XCTAssertEqual(managerB.dependencyProvider.privacyConfigData, configData)