Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion Sources/Encrypted Logs/EventLogging.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
12 changes: 11 additions & 1 deletion Tests/Tests/Event Logging/EventLoggingUploadManagerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down