diff --git a/LocalPackages/DataBrokerProtection/Sources/DataBrokerProtection/Scheduler/DataBrokerProtectionAgentManager.swift b/LocalPackages/DataBrokerProtection/Sources/DataBrokerProtection/Scheduler/DataBrokerProtectionAgentManager.swift index 22df56a835..ca406149b8 100644 --- a/LocalPackages/DataBrokerProtection/Sources/DataBrokerProtection/Scheduler/DataBrokerProtectionAgentManager.swift +++ b/LocalPackages/DataBrokerProtection/Sources/DataBrokerProtection/Scheduler/DataBrokerProtectionAgentManager.swift @@ -167,7 +167,7 @@ public final class DataBrokerProtectionAgentManager { activityScheduler.startScheduler() didStartActivityScheduler = true fireMonitoringPixels() - queueManager.startScheduledOperationsIfPermitted(showWebView: false, operationDependencies: operationDependencies, completion: nil) + queueManager.startScheduledOperationsIfPermitted(showWebView: false, operationDependencies: operationDependencies, errorHandler: nil, completion: nil) /// Monitors entitlement changes every 60 minutes to optimize system performance and resource utilization by avoiding unnecessary operations when entitlement is invalid. /// While keeping the agent active with invalid entitlement has no significant risk, setting the monitoring interval at 60 minutes is a good balance to minimize backend checks. @@ -207,15 +207,19 @@ extension DataBrokerProtectionAgentManager { extension DataBrokerProtectionAgentManager: DataBrokerProtectionBackgroundActivitySchedulerDelegate { public func dataBrokerProtectionBackgroundActivitySchedulerDidTrigger(_ activityScheduler: DataBrokerProtection.DataBrokerProtectionBackgroundActivityScheduler, completion: (() -> Void)?) { + startScheduledOperations(completion: completion) + } + + func startScheduledOperations(completion: (() -> Void)?) { fireMonitoringPixels() - queueManager.startScheduledOperationsIfPermitted(showWebView: false, operationDependencies: operationDependencies) { _ in - completion?() - } + queueManager.startScheduledOperationsIfPermitted(showWebView: false, + operationDependencies: operationDependencies, + errorHandler: nil, + completion: completion) } } extension DataBrokerProtectionAgentManager: DataBrokerProtectionAgentAppEvents { - public func profileSaved() { let backgroundAgentInitialScanStartTime = Date() @@ -245,21 +249,25 @@ extension DataBrokerProtectionAgentManager: DataBrokerProtectionAgentAppEvents { self.pixelHandler.fire(.ipcServerImmediateScansFinishedWithoutError) self.userNotificationService.sendFirstScanCompletedNotification() } + } completion: { [weak self] in + guard let self else { return } if let hasMatches = try? self.dataManager.hasMatches(), - hasMatches { + hasMatches { self.userNotificationService.scheduleCheckInNotificationIfPossible() } fireImmediateScansCompletionPixel(startTime: backgroundAgentInitialScanStartTime) + + self.startScheduledOperations(completion: nil) } } public func appLaunched() { fireMonitoringPixels() queueManager.startScheduledOperationsIfPermitted(showWebView: false, - operationDependencies: - operationDependencies) { [weak self] errors in + operationDependencies: operationDependencies, + errorHandler: { [weak self] errors in guard let self = self else { return } if let errors = errors { @@ -285,7 +293,7 @@ extension DataBrokerProtectionAgentManager: DataBrokerProtectionAgentAppEvents { if errors?.oneTimeError == nil { self.pixelHandler.fire(.ipcServerAppLaunchedScheduledScansFinishedWithoutError) } - } + }, completion: nil) } private func fireImmediateScansCompletionPixel(startTime: Date) { @@ -310,18 +318,21 @@ extension DataBrokerProtectionAgentManager: DataBrokerProtectionAgentDebugComman public func startImmediateOperations(showWebView: Bool) { queueManager.startImmediateOperationsIfPermitted(showWebView: showWebView, operationDependencies: operationDependencies, + errorHandler: nil, completion: nil) } public func startScheduledOperations(showWebView: Bool) { queueManager.startScheduledOperationsIfPermitted(showWebView: showWebView, operationDependencies: operationDependencies, + errorHandler: nil, completion: nil) } public func runAllOptOuts(showWebView: Bool) { queueManager.execute(.startOptOutOperations(showWebView: showWebView, operationDependencies: operationDependencies, + errorHandler: nil, completion: nil)) } diff --git a/LocalPackages/DataBrokerProtection/Sources/DataBrokerProtection/Scheduler/DataBrokerProtectionQueueManager.swift b/LocalPackages/DataBrokerProtection/Sources/DataBrokerProtection/Scheduler/DataBrokerProtectionQueueManager.swift index c8e2bb429b..8ed9e8dd3f 100644 --- a/LocalPackages/DataBrokerProtection/Sources/DataBrokerProtection/Scheduler/DataBrokerProtectionQueueManager.swift +++ b/LocalPackages/DataBrokerProtection/Sources/DataBrokerProtection/Scheduler/DataBrokerProtectionQueueManager.swift @@ -24,25 +24,15 @@ protocol DataBrokerProtectionOperationQueue { var maxConcurrentOperationCount: Int { get set } func cancelAllOperations() func addOperation(_ op: Operation) - func addBarrierCompletionBlock(_ barrier: @escaping @Sendable () -> Void) + func addBarrierBlock(_ barrier: @escaping @Sendable () -> Void) } -extension OperationQueue: DataBrokerProtectionOperationQueue { - /* - An unfortunute necessarity due to an issue with xcode 16 and building for Product Review Release - Originally we just used addBarrierBlock directly, but now it won't build as it says - the extension doesn't conform to the protocol - The docs however say the method signiture is unchanged, so we've decided to blame the build system - */ - func addBarrierCompletionBlock(_ barrier: @escaping @Sendable () -> Void) { - addBarrierBlock(barrier) - } -} +extension OperationQueue: DataBrokerProtectionOperationQueue {} enum DataBrokerProtectionQueueMode { case idle - case immediate(completion: ((DataBrokerProtectionAgentErrorCollection?) -> Void)?) - case scheduled(completion: ((DataBrokerProtectionAgentErrorCollection?) -> Void)?) + case immediate(errorHandler: ((DataBrokerProtectionAgentErrorCollection?) -> Void)?, completion: (() -> Void)?) + case scheduled(errorHandler: ((DataBrokerProtectionAgentErrorCollection?) -> Void)?, completion: (() -> Void)?) var priorityDate: Date? { switch self { @@ -73,7 +63,8 @@ enum DataBrokerProtectionQueueError: Error { enum DataBrokerProtectionQueueManagerDebugCommand { case startOptOutOperations(showWebView: Bool, operationDependencies: DataBrokerOperationDependencies, - completion: ((DataBrokerProtectionAgentErrorCollection?) -> Void)?) + errorHandler: ((DataBrokerProtectionAgentErrorCollection?) -> Void)?, + completion: (() -> Void)?) } protocol DataBrokerProtectionQueueManager { @@ -86,10 +77,12 @@ protocol DataBrokerProtectionQueueManager { func startImmediateOperationsIfPermitted(showWebView: Bool, operationDependencies: DataBrokerOperationDependencies, - completion: ((DataBrokerProtectionAgentErrorCollection?) -> Void)?) + errorHandler: ((DataBrokerProtectionAgentErrorCollection?) -> Void)?, + completion: (() -> Void)?) func startScheduledOperationsIfPermitted(showWebView: Bool, operationDependencies: DataBrokerOperationDependencies, - completion: ((DataBrokerProtectionAgentErrorCollection?) -> Void)?) + errorHandler: ((DataBrokerProtectionAgentErrorCollection?) -> Void)?, + completion: (() -> Void)?) func execute(_ command: DataBrokerProtectionQueueManagerDebugCommand) var debugRunningStatusString: String { get } @@ -131,37 +124,44 @@ final class DefaultDataBrokerProtectionQueueManager: DataBrokerProtectionQueueMa func startImmediateOperationsIfPermitted(showWebView: Bool, operationDependencies: DataBrokerOperationDependencies, - completion: ((DataBrokerProtectionAgentErrorCollection?) -> Void)?) { + errorHandler: ((DataBrokerProtectionAgentErrorCollection?) -> Void)?, + completion: (() -> Void)?) { - let newMode = DataBrokerProtectionQueueMode.immediate(completion: completion) + let newMode = DataBrokerProtectionQueueMode.immediate(errorHandler: errorHandler, completion: completion) startOperationsIfPermitted(forNewMode: newMode, type: .scan, showWebView: showWebView, operationDependencies: operationDependencies) { [weak self] errors in - completion?(errors) self?.mismatchCalculator.calculateMismatches() + errorHandler?(errors) + } completion: { + completion?() } } func startScheduledOperationsIfPermitted(showWebView: Bool, operationDependencies: DataBrokerOperationDependencies, - completion: ((DataBrokerProtectionAgentErrorCollection?) -> Void)?) { - let newMode = DataBrokerProtectionQueueMode.scheduled(completion: completion) + errorHandler: ((DataBrokerProtectionAgentErrorCollection?) -> Void)?, + completion: (() -> Void)?) { + let newMode = DataBrokerProtectionQueueMode.scheduled(errorHandler: errorHandler, completion: completion) startOperationsIfPermitted(forNewMode: newMode, type: .all, showWebView: showWebView, operationDependencies: operationDependencies, + errorHandler: errorHandler, completion: completion) } func execute(_ command: DataBrokerProtectionQueueManagerDebugCommand) { guard case .startOptOutOperations(let showWebView, let operationDependencies, + let errorHandler, let completion) = command else { return } addOperations(withType: .optOut, showWebView: showWebView, operationDependencies: operationDependencies, + errorHandler: errorHandler, completion: completion) } } @@ -172,12 +172,14 @@ private extension DefaultDataBrokerProtectionQueueManager { type: OperationType, showWebView: Bool, operationDependencies: DataBrokerOperationDependencies, - completion: ((DataBrokerProtectionAgentErrorCollection?) -> Void)?) { + errorHandler: ((DataBrokerProtectionAgentErrorCollection?) -> Void)?, + completion: (() -> Void)?) { guard mode.canBeInterruptedBy(newMode: newMode) else { let error = DataBrokerProtectionQueueError.cannotInterrupt let errorCollection = DataBrokerProtectionAgentErrorCollection(oneTimeError: error) - completion?(errorCollection) + errorHandler?(errorCollection) + completion?() return } @@ -191,24 +193,29 @@ private extension DefaultDataBrokerProtectionQueueManager { priorityDate: mode.priorityDate, showWebView: showWebView, operationDependencies: operationDependencies, + errorHandler: errorHandler, completion: completion) } func cancelCurrentModeAndResetIfNeeded() { switch mode { - case .immediate(let completion), .scheduled(let completion): + case .immediate(let errorHandler, let completion), .scheduled(let errorHandler, let completion): operationQueue.cancelAllOperations() let errorCollection = DataBrokerProtectionAgentErrorCollection(oneTimeError: DataBrokerProtectionQueueError.interrupted, operationErrors: operationErrorsForCurrentOperations()) - completion?(errorCollection) - resetModeAndClearErrors() + errorHandler?(errorCollection) + resetMode(clearErrors: true) + completion?() + resetMode() default: break } } - func resetModeAndClearErrors() { + func resetMode(clearErrors: Bool = false) { mode = .idle - operationErrors = [] + if clearErrors { + operationErrors = [] + } } func updateBrokerData() { @@ -220,7 +227,8 @@ private extension DefaultDataBrokerProtectionQueueManager { priorityDate: Date? = nil, showWebView: Bool, operationDependencies: DataBrokerOperationDependencies, - completion: ((DataBrokerProtectionAgentErrorCollection?) -> Void)?) { + errorHandler: ((DataBrokerProtectionAgentErrorCollection?) -> Void)?, + completion: (() -> Void)?) { operationQueue.maxConcurrentOperationCount = operationDependencies.config.concurrentOperationsFor(type) @@ -238,14 +246,17 @@ private extension DefaultDataBrokerProtectionQueueManager { } } catch { Logger.dataBrokerProtection.error("DataBrokerProtectionProcessor error: addOperations, error: \(error.localizedDescription, privacy: .public)") - completion?(DataBrokerProtectionAgentErrorCollection(oneTimeError: error)) + errorHandler?(DataBrokerProtectionAgentErrorCollection(oneTimeError: error)) + completion?() return } - operationQueue.addBarrierCompletionBlock { [weak self] in + operationQueue.addBarrierBlock { [weak self] in let errorCollection = DataBrokerProtectionAgentErrorCollection(oneTimeError: nil, operationErrors: self?.operationErrorsForCurrentOperations()) - completion?(errorCollection) - self?.resetModeAndClearErrors() + errorHandler?(errorCollection) + self?.resetMode(clearErrors: true) + completion?() + self?.resetMode() } } diff --git a/LocalPackages/DataBrokerProtection/Sources/DataBrokerProtection/Utils/Logger+DataBrokerProtection.swift b/LocalPackages/DataBrokerProtection/Sources/DataBrokerProtection/Utils/Logger+DataBrokerProtection.swift index 7d8609c26c..e92af95aa4 100644 --- a/LocalPackages/DataBrokerProtection/Sources/DataBrokerProtection/Utils/Logger+DataBrokerProtection.swift +++ b/LocalPackages/DataBrokerProtection/Sources/DataBrokerProtection/Utils/Logger+DataBrokerProtection.swift @@ -22,7 +22,7 @@ import os.log public extension Logger { fileprivate static let subsystem = "com.duckduckgo.macos.browser.databroker-protection" - static var dataBrokerProtection = { Logger(subsystem: subsystem, category: "") }() + static var dataBrokerProtection = { Logger(subsystem: subsystem, category: "Data Broker Protection") }() static var action = { Logger(subsystem: subsystem, category: "Action") }() static var service = { Logger(subsystem: subsystem, category: "Service") }() static var backgroundAgent = { Logger(subsystem: subsystem, category: "Background Agent") }() diff --git a/LocalPackages/DataBrokerProtection/Tests/DataBrokerProtectionTests/DataBrokerProtectionAgentManagerTests.swift b/LocalPackages/DataBrokerProtection/Tests/DataBrokerProtectionTests/DataBrokerProtectionAgentManagerTests.swift index d0ccaec883..0400895c38 100644 --- a/LocalPackages/DataBrokerProtection/Tests/DataBrokerProtectionTests/DataBrokerProtectionAgentManagerTests.swift +++ b/LocalPackages/DataBrokerProtection/Tests/DataBrokerProtectionTests/DataBrokerProtectionAgentManagerTests.swift @@ -99,7 +99,7 @@ final class DataBrokerProtectionAgentManagerTests: XCTestCase { let scanCalledExpectation = XCTestExpectation(description: "Scan called") var startScheduledScansCalled = false - mockQueueManager.startScheduledOperationsIfPermittedCalledCompletion = { _ in + mockQueueManager.startScheduledOperationsIfPermittedCalledCompletion = { startScheduledScansCalled = true scanCalledExpectation.fulfill() } @@ -209,7 +209,7 @@ final class DataBrokerProtectionAgentManagerTests: XCTestCase { mockDataManager.profileToReturn = mockProfile var startScheduledScansCalled = false - mockQueueManager.startScheduledOperationsIfPermittedCalledCompletion = { _ in + mockQueueManager.startScheduledOperationsIfPermittedCalledCompletion = { startScheduledScansCalled = true } @@ -237,7 +237,7 @@ final class DataBrokerProtectionAgentManagerTests: XCTestCase { mockDataManager.profileToReturn = mockProfile var startImmediateScansCalled = false - mockQueueManager.startImmediateOperationsIfPermittedCalledCompletion = { _ in + mockQueueManager.startImmediateOperationsIfPermittedCalledCompletion = { startImmediateScansCalled = true } @@ -381,7 +381,7 @@ final class DataBrokerProtectionAgentManagerTests: XCTestCase { privacyConfigurationManager: mockPrivacyConfigurationManager) var startScheduledScansCalled = false - mockQueueManager.startScheduledOperationsIfPermittedCalledCompletion = { _ in + mockQueueManager.startScheduledOperationsIfPermittedCalledCompletion = { startScheduledScansCalled = true } diff --git a/LocalPackages/DataBrokerProtection/Tests/DataBrokerProtectionTests/DataBrokerProtectionQueueManagerTests.swift b/LocalPackages/DataBrokerProtection/Tests/DataBrokerProtectionTests/DataBrokerProtectionQueueManagerTests.swift index e69d984c64..2e04273131 100644 --- a/LocalPackages/DataBrokerProtection/Tests/DataBrokerProtectionTests/DataBrokerProtectionQueueManagerTests.swift +++ b/LocalPackages/DataBrokerProtection/Tests/DataBrokerProtectionTests/DataBrokerProtectionQueueManagerTests.swift @@ -53,7 +53,7 @@ final class DataBrokerProtectionQueueManagerTests: XCTestCase { userNotificationService: mockUserNotification) } - func testWhenStartImmediateScan_andScanCompletesWithErrors_thenCompletionIsCalledWithErrors() async throws { + func testWhenStartImmediateScan_andScanCompletesWithErrors_thenErrorHandleIsCalledWithErrors_followedByCompletionBlock() async throws { // Given sut = DefaultDataBrokerProtectionQueueManager(operationQueue: mockQueue, operationsCreator: mockOperationsCreator, @@ -63,14 +63,18 @@ final class DataBrokerProtectionQueueManagerTests: XCTestCase { let mockOperation = MockDataBrokerOperation(id: 1, operationType: .scan, errorDelegate: sut) let mockOperationWithError = MockDataBrokerOperation(id: 2, operationType: .scan, errorDelegate: sut, shouldError: true) mockOperationsCreator.operationCollections = [mockOperation, mockOperationWithError] - let expectation = expectation(description: "Expected errors to be returned in completion") + let expectation = expectation(description: "Expected completion to be called") var errorCollection: DataBrokerProtectionAgentErrorCollection! let expectedConcurrentOperations = DataBrokerExecutionConfig().concurrentOperationsFor(.scan) + var errorHandlerCalled = false // When sut.startImmediateOperationsIfPermitted(showWebView: false, operationDependencies: mockDependencies) { errors in errorCollection = errors + errorHandlerCalled = true + } completion: { + XCTAssertTrue(errorHandlerCalled) expectation.fulfill() } @@ -83,7 +87,7 @@ final class DataBrokerProtectionQueueManagerTests: XCTestCase { XCTAssertEqual(mockQueue.maxConcurrentOperationCount, expectedConcurrentOperations) } - func testWhenStartScheduledScan_andScanCompletesWithErrors_thenCompletionIsCalledWithErrors() async throws { + func testWhenStartScheduledScan_andScanCompletesWithErrors_thenErrorHandlerIsCalledWithErrors_followedByCompletionBlock() async throws { // Given sut = DefaultDataBrokerProtectionQueueManager(operationQueue: mockQueue, operationsCreator: mockOperationsCreator, @@ -93,14 +97,18 @@ final class DataBrokerProtectionQueueManagerTests: XCTestCase { let mockOperation = MockDataBrokerOperation(id: 1, operationType: .scan, errorDelegate: sut) let mockOperationWithError = MockDataBrokerOperation(id: 2, operationType: .scan, errorDelegate: sut, shouldError: true) mockOperationsCreator.operationCollections = [mockOperation, mockOperationWithError] - let expectation = expectation(description: "Expected errors to be returned in completion") + let expectation = expectation(description: "Expected completion to be called") var errorCollection: DataBrokerProtectionAgentErrorCollection! let expectedConcurrentOperations = DataBrokerExecutionConfig().concurrentOperationsFor(.all) + var errorHandlerCalled = false // When sut.startScheduledOperationsIfPermitted(showWebView: false, operationDependencies: mockDependencies) { errors in errorCollection = errors + errorHandlerCalled = true + } completion: { + XCTAssertTrue(errorHandlerCalled) expectation.fulfill() } @@ -128,6 +136,8 @@ final class DataBrokerProtectionQueueManagerTests: XCTestCase { // When sut.startScheduledOperationsIfPermitted(showWebView: false, operationDependencies: mockDependencies) { errors in errorCollection = errors + } completion: { + // no-op } mockQueue.completeOperationsUpTo(index: 2) @@ -140,7 +150,10 @@ final class DataBrokerProtectionQueueManagerTests: XCTestCase { mockOperationsCreator.operationCollections = mockOperations // When - sut.startImmediateOperationsIfPermitted(showWebView: false, operationDependencies: mockDependencies) { _ in } + sut.startImmediateOperationsIfPermitted(showWebView: false, operationDependencies: mockDependencies) { _ in + } completion: { + // no-op + } // Then XCTAssert(errorCollection.operationErrors?.count == 2) @@ -166,6 +179,8 @@ final class DataBrokerProtectionQueueManagerTests: XCTestCase { // When sut.startImmediateOperationsIfPermitted(showWebView: false, operationDependencies: mockDependencies) { errors in errorCollection = errors + } completion: { + // no-op } mockQueue.completeOperationsUpTo(index: 2) @@ -178,7 +193,10 @@ final class DataBrokerProtectionQueueManagerTests: XCTestCase { mockOperationsCreator.operationCollections = mockOperations // When - sut.startImmediateOperationsIfPermitted(showWebView: false, operationDependencies: mockDependencies) { _ in } + sut.startImmediateOperationsIfPermitted(showWebView: false, operationDependencies: mockDependencies) { _ in + } completion: { + // no-op + } // Then XCTAssert(errorCollection.operationErrors?.count == 2) @@ -204,6 +222,8 @@ final class DataBrokerProtectionQueueManagerTests: XCTestCase { // When sut.startImmediateOperationsIfPermitted(showWebView: false, operationDependencies: mockDependencies) { errors in errorCollectionFirst = errors + } completion: { + // no-op } mockQueue.completeOperationsUpTo(index: 2) @@ -220,6 +240,8 @@ final class DataBrokerProtectionQueueManagerTests: XCTestCase { // When sut.startImmediateOperationsIfPermitted(showWebView: false, operationDependencies: mockDependencies) { errors in errorCollectionSecond = errors + } completion: { + // no-op } mockQueue.completeAllOperations() @@ -246,7 +268,10 @@ final class DataBrokerProtectionQueueManagerTests: XCTestCase { var errorCollection: DataBrokerProtectionAgentErrorCollection! // When - sut.startImmediateOperationsIfPermitted(showWebView: false, operationDependencies: mockDependencies) { _ in } + sut.startImmediateOperationsIfPermitted(showWebView: false, operationDependencies: mockDependencies) { _ in + } completion: { + // no-op + } // Then XCTAssert(mockQueue.operationCount == 10) @@ -264,6 +289,7 @@ final class DataBrokerProtectionQueueManagerTests: XCTestCase { // When sut.startScheduledOperationsIfPermitted(showWebView: false, operationDependencies: mockDependencies) { errors in errorCollection = errors + } completion: { completionCalled.toggle() } @@ -290,6 +316,7 @@ final class DataBrokerProtectionQueueManagerTests: XCTestCase { sut.startImmediateOperationsIfPermitted(showWebView: false, operationDependencies: mockDependencies) { errors in errorCollection = errors + } completion: { expectation.fulfill() } @@ -311,6 +338,7 @@ final class DataBrokerProtectionQueueManagerTests: XCTestCase { // When sut.execute(.startOptOutOperations(showWebView: false, operationDependencies: mockDependencies, + errorHandler: nil, completion: nil)) // Then diff --git a/LocalPackages/DataBrokerProtection/Tests/DataBrokerProtectionTests/DataBrokerProtectionQueueModeTests.swift b/LocalPackages/DataBrokerProtection/Tests/DataBrokerProtectionTests/DataBrokerProtectionQueueModeTests.swift index ef2ab05b38..837eb40cdb 100644 --- a/LocalPackages/DataBrokerProtection/Tests/DataBrokerProtectionTests/DataBrokerProtectionQueueModeTests.swift +++ b/LocalPackages/DataBrokerProtection/Tests/DataBrokerProtectionTests/DataBrokerProtectionQueueModeTests.swift @@ -26,7 +26,7 @@ final class DataBrokerProtectionQueueModeTests: XCTestCase { let sut = DataBrokerProtectionQueueMode.idle // When - let result = sut.canBeInterruptedBy(newMode: .immediate(completion: nil)) + let result = sut.canBeInterruptedBy(newMode: .immediate(errorHandler: nil, completion: nil)) // Then XCTAssertTrue(result) @@ -37,7 +37,7 @@ final class DataBrokerProtectionQueueModeTests: XCTestCase { let sut = DataBrokerProtectionQueueMode.idle // When - let result = sut.canBeInterruptedBy(newMode: .scheduled(completion: nil)) + let result = sut.canBeInterruptedBy(newMode: .scheduled(errorHandler: nil, completion: nil)) // Then XCTAssertTrue(result) @@ -45,10 +45,10 @@ final class DataBrokerProtectionQueueModeTests: XCTestCase { func testCurrentModeImmediate_andNewModeImmediate_thenInterruptionAllowed() throws { // Given - let sut = DataBrokerProtectionQueueMode.immediate(completion: nil) + let sut = DataBrokerProtectionQueueMode.immediate(errorHandler: nil, completion: nil) // When - let result = sut.canBeInterruptedBy(newMode: .immediate(completion: { _ in })) + let result = sut.canBeInterruptedBy(newMode: .immediate(errorHandler: { _ in }, completion: {})) // Then XCTAssertTrue(result) @@ -56,10 +56,10 @@ final class DataBrokerProtectionQueueModeTests: XCTestCase { func testCurrentModeImmediate_andNewModeScheduled_thenInterruptionNotAllowed() throws { // Given - let sut = DataBrokerProtectionQueueMode.immediate(completion: nil) + let sut = DataBrokerProtectionQueueMode.immediate(errorHandler: nil, completion: nil) // When - let result = sut.canBeInterruptedBy(newMode: .scheduled(completion: nil)) + let result = sut.canBeInterruptedBy(newMode: .scheduled(errorHandler: nil, completion: nil)) // Then XCTAssertFalse(result) @@ -67,10 +67,10 @@ final class DataBrokerProtectionQueueModeTests: XCTestCase { func testCurrentModeScheduled_andNewModeImmediate_thenInterruptionAllowed() throws { // Given - let sut = DataBrokerProtectionQueueMode.scheduled(completion: nil) + let sut = DataBrokerProtectionQueueMode.scheduled(errorHandler: nil, completion: nil) // When - let result = sut.canBeInterruptedBy(newMode: .immediate(completion: nil)) + let result = sut.canBeInterruptedBy(newMode: .immediate(errorHandler: nil, completion: nil)) // Then XCTAssertTrue(result) @@ -78,10 +78,10 @@ final class DataBrokerProtectionQueueModeTests: XCTestCase { func testCurrentModeScheduled_andNewModeScheduled_thenInterruptionNotAllowed() throws { // Given - let sut = DataBrokerProtectionQueueMode.scheduled(completion: nil) + let sut = DataBrokerProtectionQueueMode.scheduled(errorHandler: nil, completion: nil) // When - let result = sut.canBeInterruptedBy(newMode: .scheduled(completion: nil)) + let result = sut.canBeInterruptedBy(newMode: .scheduled(errorHandler: nil, completion: nil)) // Then XCTAssertFalse(result) @@ -100,7 +100,7 @@ final class DataBrokerProtectionQueueModeTests: XCTestCase { func testWhenModeIsImmediate_thenPriorityDateIsNil() throws { // Given - let sut = DataBrokerProtectionQueueMode.immediate(completion: nil) + let sut = DataBrokerProtectionQueueMode.immediate(errorHandler: nil, completion: nil) // When let result = sut.priorityDate @@ -111,7 +111,7 @@ final class DataBrokerProtectionQueueModeTests: XCTestCase { func testWhenModeIsScheduled_thenPriorityDateIsNotNil() throws { // Given - let sut = DataBrokerProtectionQueueMode.scheduled(completion: nil) + let sut = DataBrokerProtectionQueueMode.scheduled(errorHandler: nil, completion: nil) // When let result = sut.priorityDate diff --git a/LocalPackages/DataBrokerProtection/Tests/DataBrokerProtectionTests/Mocks.swift b/LocalPackages/DataBrokerProtection/Tests/DataBrokerProtectionTests/Mocks.swift index 023a1c9f55..d0a0bcf970 100644 --- a/LocalPackages/DataBrokerProtection/Tests/DataBrokerProtectionTests/Mocks.swift +++ b/LocalPackages/DataBrokerProtection/Tests/DataBrokerProtectionTests/Mocks.swift @@ -1208,21 +1208,23 @@ final class MockDataBrokerProtectionOperationQueueManager: DataBrokerProtectionQ var startImmediateOperationsIfPermittedCompletionError: DataBrokerProtectionAgentErrorCollection? var startScheduledOperationsIfPermittedCompletionError: DataBrokerProtectionAgentErrorCollection? - var startImmediateOperationsIfPermittedCalledCompletion: ((DataBrokerProtection.DataBrokerProtectionAgentErrorCollection?) -> Void)? - var startScheduledOperationsIfPermittedCalledCompletion: ((DataBrokerProtection.DataBrokerProtectionAgentErrorCollection?) -> Void)? + var startImmediateOperationsIfPermittedCalledCompletion: (() -> Void)? + var startScheduledOperationsIfPermittedCalledCompletion: (() -> Void)? init(operationQueue: DataBrokerProtection.DataBrokerProtectionOperationQueue, operationsCreator: DataBrokerProtection.DataBrokerOperationsCreator, mismatchCalculator: DataBrokerProtection.MismatchCalculator, brokerUpdater: DataBrokerProtection.DataBrokerProtectionBrokerUpdater?, pixelHandler: Common.EventMapping) { } - func startImmediateOperationsIfPermitted(showWebView: Bool, operationDependencies: DataBrokerProtection.DataBrokerOperationDependencies, completion: ((DataBrokerProtection.DataBrokerProtectionAgentErrorCollection?) -> Void)?) { - completion?(startImmediateOperationsIfPermittedCompletionError) - startImmediateOperationsIfPermittedCalledCompletion?(startImmediateOperationsIfPermittedCompletionError) + func startImmediateOperationsIfPermitted(showWebView: Bool, operationDependencies: any DataBrokerProtection.DataBrokerOperationDependencies, errorHandler: ((DataBrokerProtection.DataBrokerProtectionAgentErrorCollection?) -> Void)?, completion: (() -> Void)?) { + errorHandler?(startImmediateOperationsIfPermittedCompletionError) + completion?() + startImmediateOperationsIfPermittedCalledCompletion?() } - func startScheduledOperationsIfPermitted(showWebView: Bool, operationDependencies: DataBrokerProtection.DataBrokerOperationDependencies, completion: ((DataBrokerProtection.DataBrokerProtectionAgentErrorCollection?) -> Void)?) { - completion?(startScheduledOperationsIfPermittedCompletionError) - startScheduledOperationsIfPermittedCalledCompletion?(startScheduledOperationsIfPermittedCompletionError) + func startScheduledOperationsIfPermitted(showWebView: Bool, operationDependencies: any DataBrokerProtection.DataBrokerOperationDependencies, errorHandler: ((DataBrokerProtection.DataBrokerProtectionAgentErrorCollection?) -> Void)?, completion: (() -> Void)?) { + errorHandler?(startScheduledOperationsIfPermittedCompletionError) + completion?() + startScheduledOperationsIfPermittedCalledCompletion?() } func execute(_ command: DataBrokerProtection.DataBrokerProtectionQueueManagerDebugCommand) { @@ -1386,7 +1388,7 @@ final class MockDataBrokerProtectionOperationQueue: DataBrokerProtectionOperatio self.operations.append(op) } - func addBarrierCompletionBlock(_ barrier: @escaping @Sendable () -> Void) { + func addBarrierBlock(_ barrier: @escaping @Sendable () -> Void) { didCallAddBarrierBlockCount += 1 self.barrierBlock = barrier }