Skip to content

Commit

Permalink
Fix ConfigurationManagerTests
Browse files Browse the repository at this point in the history
  • Loading branch information
ayoy committed Sep 24, 2024
1 parent 28c03b8 commit 86f6b4c
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions Tests/ConfigurationTests/ConfigurationManagerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 = XCTestExpectation(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)
Expand All @@ -152,33 +151,31 @@ final class ConfigurationManagerTests: XCTestCase {
let managerA = makeConfigurationManager()
let managerB = makeConfigurationManager()

var e: XCTestExpectation? = expectation(description: "ConfigManager B updated")
var e = XCTestExpectation(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)
XCTAssertEqual(managerB.dependencyProvider.privacyConfigEtag, HTTPURLResponse.testEtag)

MockURLProtocol.lastRequest = nil
e = expectation(description: "ConfigManager A updated")
e = XCTestExpectation(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)
Expand All @@ -197,16 +194,15 @@ final class ConfigurationManagerTests: XCTestCase {
let managerA = makeConfigurationManager()
let managerB = makeConfigurationManager()

var e: XCTestExpectation? = expectation(description: "ConfigManager B updated")
let e = XCTestExpectation(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)
Expand Down

0 comments on commit 86f6b4c

Please sign in to comment.