From 2cc53c64ac1369681c153a72998eadb78260cb2e Mon Sep 17 00:00:00 2001 From: Nick Cooke Date: Wed, 19 Mar 2025 10:36:26 -0400 Subject: [PATCH 1/2] [Swift 6] Add Swift 6 testing for Sessions --- .../FirebaseSessionsTests+BaseBehaviors.swift | 2 +- .../Tests/Unit/InitiatorTests.swift | 2 +- .../Unit/Library/LifecycleNotifications.swift | 26 ++----------------- 3 files changed, 4 insertions(+), 26 deletions(-) diff --git a/FirebaseSessions/Tests/Unit/FirebaseSessionsTests+BaseBehaviors.swift b/FirebaseSessions/Tests/Unit/FirebaseSessionsTests+BaseBehaviors.swift index 2c453a4518a..c1b02cc38aa 100644 --- a/FirebaseSessions/Tests/Unit/FirebaseSessionsTests+BaseBehaviors.swift +++ b/FirebaseSessions/Tests/Unit/FirebaseSessionsTests+BaseBehaviors.swift @@ -87,7 +87,7 @@ final class FirebaseSessionsTestsBase_BaseBehaviors: FirebaseSessionsTestsBase { // We wanted to make sure that since we've introduced promises, // once the promise has been fulfilled, that .then'ing on the promise // in future initiations still results in a log - func test_multipleInitiations_logsSessionEventEachInitiation() { + @MainActor func test_multipleInitiations_logsSessionEventEachInitiation() { var loggedCount = 0 var lastLoggedSessionID = "" let loggedTwiceExpectation = expectation(description: "Sessions SDK logged events twice") diff --git a/FirebaseSessions/Tests/Unit/InitiatorTests.swift b/FirebaseSessions/Tests/Unit/InitiatorTests.swift index c3b17fb3dde..ebb6be2b5bc 100644 --- a/FirebaseSessions/Tests/Unit/InitiatorTests.swift +++ b/FirebaseSessions/Tests/Unit/InitiatorTests.swift @@ -58,7 +58,7 @@ class InitiatorTests: XCTestCase { XCTAssert(initiateCalled) } - func test_appForegrounded_initiatesNewSession() throws { + @MainActor func test_appForegrounded_initiatesNewSession() throws { // Given var pausedClock = date let initiator = SessionInitiator( diff --git a/FirebaseSessions/Tests/Unit/Library/LifecycleNotifications.swift b/FirebaseSessions/Tests/Unit/Library/LifecycleNotifications.swift index 80c6f7c38f9..e2ea9d54e9d 100644 --- a/FirebaseSessions/Tests/Unit/Library/LifecycleNotifications.swift +++ b/FirebaseSessions/Tests/Unit/Library/LifecycleNotifications.swift @@ -37,18 +37,7 @@ import Dispatch #endif // swift(>=5.9) extension XCTestCase { - func postBackgroundedNotification() { - // On Catalyst, the notifications can only be called on a the main thread - if Thread.isMainThread { - postBackgroundedNotificationInternal() - } else { - DispatchQueue.main.sync { - self.postBackgroundedNotificationInternal() - } - } - } - - private func postBackgroundedNotificationInternal() { + @MainActor func postBackgroundedNotification() { let notificationCenter = NotificationCenter.default #if os(iOS) || os(tvOS) notificationCenter.post(name: UIApplication.didEnterBackgroundNotification, object: nil) @@ -74,18 +63,7 @@ extension XCTestCase { #endif // swift(>=5.9) } - func postForegroundedNotification() { - // On Catalyst, the notifications can only be called on a the main thread - if Thread.isMainThread { - postForegroundedNotificationInternal() - } else { - DispatchQueue.main.sync { - self.postForegroundedNotificationInternal() - } - } - } - - private func postForegroundedNotificationInternal() { + @MainActor func postForegroundedNotification() { let notificationCenter = NotificationCenter.default #if os(iOS) || os(tvOS) notificationCenter.post(name: UIApplication.didBecomeActiveNotification, object: nil) From 5fd7a3100a288cd64bd2f17f1293f9fad25fdb6b Mon Sep 17 00:00:00 2001 From: Nick Cooke Date: Wed, 19 Mar 2025 10:41:09 -0400 Subject: [PATCH 2/2] [Swift 6] Add regression tests in CI --- .github/workflows/sessions.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/workflows/sessions.yml b/.github/workflows/sessions.yml index e30510d6fdd..668a1b674db 100644 --- a/.github/workflows/sessions.yml +++ b/.github/workflows/sessions.yml @@ -28,10 +28,17 @@ jobs: - os: macos-14 xcode: Xcode_15.3 tests: + swift_version: 5.9 # Flaky tests on CI - os: macos-15 xcode: Xcode_16.2 tests: --skip-tests + swift_version: 5.9 + # Flaky tests on CI + - os: macos-15 + xcode: Xcode_16.2 + tests: --skip-tests + swift_version: 6.0 runs-on: ${{ matrix.build-env.os }} steps: - uses: actions/checkout@v4 @@ -40,6 +47,8 @@ jobs: run: scripts/setup_bundler.sh - name: Xcode run: sudo xcode-select -s /Applications/${{ matrix.build-env.xcode }}.app/Contents/Developer + - name: Set Swift swift_version + run: sed -i "" "s/s.swift_version[[:space:]]*=[[:space:]]*'5.9'/s.swift_version = '${{ matrix.build-env.swift_version }}'/" FirebaseSessions.podspec - uses: nick-fields/retry@v3 with: timeout_minutes: 120