diff --git a/Sources/Encrypted Logs/EventLogging.swift b/Sources/Encrypted Logs/EventLogging.swift index 9834772f..743e66c0 100644 --- a/Sources/Encrypted Logs/EventLogging.swift +++ b/Sources/Encrypted Logs/EventLogging.swift @@ -21,6 +21,7 @@ public class EventLogging { /// Coordinates one-at-a-time file log dequeuing and upload private let lock = NSLock() private let processingQueue = DispatchQueue(label: "event-logging-upload") + private var uploadsPausedByDelegate = false /// Uploads Events private let uploadManager: EventLoggingUploadManager @@ -98,10 +99,23 @@ extension EventLogging { return } + if uploadsPausedByDelegate { + // Delegate cancellation is a policy pause rather than a backoff retry: + // stay idle until uploads are explicitly allowed again + guard delegate.shouldUploadLogFiles else { + lock.unlock() + return + } + + // Clear the pause state once the delegate allows uploads again so queued + // logs can resume on this run + uploadsPausedByDelegate = false + } + /// If the delegate is reporting that we shouldn't upload log files, pause upload to prevent an endless loop guard delegate.shouldUploadLogFiles else { + uploadsPausedByDelegate = true delegate.uploadCancelledByDelegate(log) - retryUploadsAt(.distantFuture) lock.unlock() return } diff --git a/Tests/Tests/Event Logging/EventLoggingUploadManagerTests.swift b/Tests/Tests/Event Logging/EventLoggingUploadManagerTests.swift index cf45e79a..31e318a2 100644 --- a/Tests/Tests/Event Logging/EventLoggingUploadManagerTests.swift +++ b/Tests/Tests/Event Logging/EventLoggingUploadManagerTests.swift @@ -16,7 +16,17 @@ class EventLoggingUploadManagerTests: XCTestCase { let uploadManager = self.uploadManager(delegate: delegate) waitForExpectation(timeout: 1.0) { exp in - uploadManager.upload(LogFile.containingRandomString(), then: { _ in exp.fulfill() }) + // The upload callback fires before `didFinishUploadingLog`, so wait for both + // to avoid asserting on delegate state before the upload fully settles + exp.expectedFulfillmentCount = 2 + + delegate.withDidFinishUploadingCallback { _ in + exp.fulfill() + } + + uploadManager.upload(LogFile.containingRandomString(), then: { _ in + exp.fulfill() + }) } XCTAssertTrue(delegate.didStartUploadingTriggered)