Jelajahi Sumber

[Infra] Sessions Xcode 26 beta warnings (#15100)

Nick Cooke 8 bulan lalu
induk
melakukan
0842f0a43f

+ 4 - 2
FirebaseSessions/Sources/EventGDTLogger.swift

@@ -18,7 +18,8 @@ import Foundation
 internal import GoogleDataTransport
 
 protocol EventGDTLoggerProtocol: Sendable {
-  func logEvent(event: SessionStartEvent, completion: @escaping (Result<Void, Error>) -> Void)
+  func logEvent(event: SessionStartEvent,
+                completion: @escaping @Sendable (Result<Void, Error>) -> Void)
 }
 
 ///
@@ -38,7 +39,8 @@ final class EventGDTLogger: EventGDTLoggerProtocol {
 
   /// Logs the event to FireLog, taking into account debugging cases such as running
   /// in simulator.
-  func logEvent(event: SessionStartEvent, completion: @escaping (Result<Void, Error>) -> Void) {
+  func logEvent(event: SessionStartEvent,
+                completion: @escaping @Sendable (Result<Void, Error>) -> Void) {
     let gdtEvent = googleDataTransport.eventForTransport()
     gdtEvent.dataObject = event
     gdtEvent.qosTier = GDTCOREventQoS.qosDefault

+ 4 - 2
FirebaseSessions/Sources/GoogleDataTransport+GoogleDataTransportProtocol.swift

@@ -22,7 +22,8 @@ enum GoogleDataTransportProtocolErrors: Error {
 }
 
 protocol GoogleDataTransportProtocol: Sendable {
-  func logGDTEvent(event: GDTCOREvent, completion: @escaping (Result<Void, Error>) -> Void)
+  func logGDTEvent(event: GDTCOREvent,
+                   completion: @escaping @Sendable (Result<Void, Error>) -> Void)
   func eventForTransport() -> GDTCOREvent
 }
 
@@ -38,7 +39,8 @@ final class GoogleDataTransporter: GoogleDataTransportProtocol {
     transporter = GDTCORTransport(mappingID: mappingID, transformers: transformers, target: target)!
   }
 
-  func logGDTEvent(event: GDTCOREvent, completion: @escaping (Result<Void, any Error>) -> Void) {
+  func logGDTEvent(event: GDTCOREvent,
+                   completion: @escaping @Sendable (Result<Void, any Error>) -> Void) {
     transporter.sendDataEvent(event) { wasWritten, error in
       if let error {
         completion(.failure(error))

+ 6 - 2
FirebaseSessions/Sources/SessionCoordinator.swift

@@ -16,7 +16,8 @@ import Foundation
 
 protocol SessionCoordinatorProtocol: Sendable {
   func attemptLoggingSessionStart(event: SessionStartEvent,
-                                  callback: @escaping (Result<Void, FirebaseSessionsError>) -> Void)
+                                  callback: @escaping @Sendable (Result<Void,
+                                    FirebaseSessionsError>) -> Void)
 }
 
 ///
@@ -37,7 +38,10 @@ final class SessionCoordinator: SessionCoordinatorProtocol {
   /// Begins the process of logging a SessionStartEvent to FireLog after
   /// it has been approved for sending
   func attemptLoggingSessionStart(event: SessionStartEvent,
-                                  callback: @escaping (Result<Void, FirebaseSessionsError>)
+                                  callback: @escaping @Sendable (Result<
+                                    Void,
+                                    FirebaseSessionsError
+                                  >)
                                     -> Void) {
     /// Order of execution
     /// 1. Fetch the installations Id. Regardless of success, move to step 2

+ 23 - 16
FirebaseSessions/Tests/Unit/SessionCoordinatorTests.swift

@@ -17,6 +17,13 @@ import XCTest
 
 @testable import FirebaseSessions
 
+private class SendableBox<Value>: @unchecked Sendable {
+  var value: Value
+  init(value: Value) {
+    self.value = value
+  }
+}
+
 class SessionCoordinatorTests: XCTestCase {
   var installations = MockInstallationsProtocol()
   var time = MockTimeProvider()
@@ -50,13 +57,13 @@ class SessionCoordinatorTests: XCTestCase {
 
   func test_attemptLoggingSessionStart_logsToGDT() throws {
     let event = SessionStartEvent(sessionInfo: defaultSessionInfo, appInfo: appInfo, time: time)
-    var resultSuccess = false
+    let resultSuccess = SendableBox(value: false)
     coordinator.attemptLoggingSessionStart(event: event) { result in
       switch result {
       case .success(()):
-        resultSuccess = true
+        resultSuccess.value = true
       case .failure:
-        resultSuccess = false
+        resultSuccess.value = false
       }
     }
     // Make sure we've set the Installation ID
@@ -71,7 +78,7 @@ class SessionCoordinatorTests: XCTestCase {
 
     // We should have logged successfully
     XCTAssertEqual(fireLogger.loggedEvent, event)
-    XCTAssert(resultSuccess)
+    XCTAssert(resultSuccess.value)
   }
 
   func test_attemptLoggingSessionStart_handlesGDTError() throws {
@@ -80,13 +87,13 @@ class SessionCoordinatorTests: XCTestCase {
     let event = SessionStartEvent(sessionInfo: defaultSessionInfo, appInfo: appInfo, time: time)
 
     // Start success so it must be set to false
-    var resultSuccess = true
+    let resultSuccess = SendableBox(value: true)
     coordinator.attemptLoggingSessionStart(event: event) { result in
       switch result {
       case .success(()):
-        resultSuccess = true
+        resultSuccess.value = true
       case .failure:
-        resultSuccess = false
+        resultSuccess.value = false
       }
     }
 
@@ -102,7 +109,7 @@ class SessionCoordinatorTests: XCTestCase {
 
     // We should have logged the event, but with a failed result
     XCTAssertEqual(fireLogger.loggedEvent, event)
-    XCTAssertFalse(resultSuccess)
+    XCTAssertFalse(resultSuccess.value)
   }
 
   func test_attemptLoggingSessionStart_handlesInstallationsError() throws {
@@ -111,13 +118,13 @@ class SessionCoordinatorTests: XCTestCase {
     let event = SessionStartEvent(sessionInfo: defaultSessionInfo, appInfo: appInfo, time: time)
 
     // Start success so it must be set to false
-    var resultSuccess = true
+    let resultSuccess = SendableBox(value: true)
     coordinator.attemptLoggingSessionStart(event: event) { result in
       switch result {
       case .success(()):
-        resultSuccess = true
+        resultSuccess.value = true
       case .failure:
-        resultSuccess = false
+        resultSuccess.value = false
       }
     }
 
@@ -125,7 +132,7 @@ class SessionCoordinatorTests: XCTestCase {
     XCTAssertTrue(installations.installationIdFinished)
     // We should have logged the event, but with a failed result
     XCTAssertNotNil(fireLogger.loggedEvent)
-    XCTAssertFalse(resultSuccess)
+    XCTAssertFalse(resultSuccess.value)
   }
 
   func test_attemptLoggingSessionStart_handlesGDTAndInstallationsError() throws {
@@ -138,13 +145,13 @@ class SessionCoordinatorTests: XCTestCase {
     let event = SessionStartEvent(sessionInfo: defaultSessionInfo, appInfo: appInfo, time: time)
 
     // Start success so it must be set to false
-    var resultSuccess = true
+    let resultSuccess = SendableBox(value: true)
     coordinator.attemptLoggingSessionStart(event: event) { result in
       switch result {
       case .success(()):
-        resultSuccess = true
+        resultSuccess.value = true
       case let .failure(err):
-        resultSuccess = false
+        resultSuccess.value = false
         // Result should use the FireLog error if there's an error in both
         // Installations and FireLog
         XCTAssertEqual(err, FirebaseSessionsError.DataTransportError(fireLogError))
@@ -164,6 +171,6 @@ class SessionCoordinatorTests: XCTestCase {
 
     // We should have logged the event, but with a failed result
     XCTAssertEqual(fireLogger.loggedEvent, event)
-    XCTAssertFalse(resultSuccess)
+    XCTAssertFalse(resultSuccess.value)
   }
 }