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 8891bdf
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 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 = expectation(description: "ConfigManager B updated")
managerB.onDependenciesUpdated = {
e?.fulfill()
e = nil
e.fulfill()

Check failure on line 137 in Tests/ConfigurationTests/ConfigurationManagerTests.swift

View workflow job for this annotation

GitHub Actions / Run unit tests (macOS)

testWhenManagerBReceivesNewDataManagerAHasDataAfter304Response, API violation - multiple calls made to -[XCTestExpectation fulfill] for ConfigManager B updated. (NSInternalInconsistencyException)
}

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,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)
Expand All @@ -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)
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 = expectation(description: "ConfigManager B updated")
managerB.onDependenciesUpdated = {
e?.fulfill()
e = nil
e.fulfill()

Check failure on line 199 in Tests/ConfigurationTests/ConfigurationManagerTests.swift

View workflow job for this annotation

GitHub Actions / Run unit tests (macOS)

testWhenManagerBReceivesNewDataManagerAHasDataAfter304Response, API violation - multiple calls made to -[XCTestExpectation fulfill] for ConfigManager B updated. (NSInternalInconsistencyException)
}

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 8891bdf

Please sign in to comment.