diff --git a/FirebaseSessions/Sources/FirebaseSessions.swift b/FirebaseSessions/Sources/FirebaseSessions.swift index 0894bf2a028..fa3e4c05f43 100644 --- a/FirebaseSessions/Sources/FirebaseSessions.swift +++ b/FirebaseSessions/Sources/FirebaseSessions.swift @@ -135,9 +135,12 @@ private enum GoogleDataTransportConfig { } // Initializes the SDK and begins the process of listening for lifecycle events and logging - // events. `logEventCallback` is invoked on a global background queue. + // events. The given `logEventCallback` is invoked on a global background queue by default, + // but configurable via `loggedEventCallbackQueue` for providing a higher priority queue + // during tests to reduce flakes. init(appID: String, sessionGenerator: SessionGenerator, coordinator: SessionCoordinatorProtocol, initiator: SessionInitiator, appInfo: ApplicationInfoProtocol, settings: SettingsProtocol, + loggedEventCallbackQueue: DispatchQueue = .global(qos: .background), loggedEventCallback: @escaping @Sendable (Result) -> Void) { self.appID = appID @@ -179,7 +182,7 @@ private enum GoogleDataTransportConfig { // Wait until all subscriber promises have been fulfilled before // doing any data collection. - all(self.subscriberPromises.values).then(on: .global(qos: .background)) { _ in + all(self.subscriberPromises.values).then(on: loggedEventCallbackQueue) { _ in guard self.isAnyDataCollectionEnabled else { loggedEventCallback(.failure(.DataCollectionError)) return diff --git a/FirebaseSessions/Tests/Unit/Library/FirebaseSessionsTestsBase.swift b/FirebaseSessions/Tests/Unit/Library/FirebaseSessionsTestsBase.swift index 86d1c24131c..7ad39614fda 100644 --- a/FirebaseSessions/Tests/Unit/Library/FirebaseSessionsTestsBase.swift +++ b/FirebaseSessions/Tests/Unit/Library/FirebaseSessionsTestsBase.swift @@ -110,7 +110,9 @@ class FirebaseSessionsTestsBase: XCTestCase { coordinator: mockCoordinator, initiator: initiator, appInfo: mockAppInfo, - settings: mockSettings) { result in + settings: mockSettings, + // Execute the callback on a higher priority queue to avoid test flakes. + loggedEventCallbackQueue: .global(qos: .userInteractive)) { result in DispatchQueue.main.async { // Provide the result for tests to test against postLogEvent(result, subscriberSDKs)