Skip to content

[Swift 6] Add Swift 6 testing for Sessions #14599

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
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
9 changes: 9 additions & 0 deletions .github/workflows/sessions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,17 @@ jobs:
- os: macos-14
xcode: Xcode_16.2
tests:
swift_version: 5.9
# Flaky tests on CI
- os: macos-15
xcode: Xcode_16.3
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
Expand All @@ -51,6 +58,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@ce71cc2ab81d554ebbe88c79ab5975992d79ba08 # v3
with:
timeout_minutes: 120
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
// 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")
Expand Down Expand Up @@ -138,10 +138,10 @@
}
)

wait(for: [loggedTwiceExpectation], timeout: 3)

Check failure on line 141 in FirebaseSessions/Tests/Unit/FirebaseSessionsTests+BaseBehaviors.swift

View workflow job for this annotation

GitHub Actions / spm / spm (macos-15, Xcode_16.3, visionOS)

test_multipleInitiations_logsSessionEventEachInitiation, Asynchronous wait failed: Exceeded timeout of 3 seconds, with unfulfilled expectations: "Sessions SDK logged events twice".

// Make sure we logged 2 events
XCTAssertEqual(loggedCount, 2)

Check failure on line 144 in FirebaseSessions/Tests/Unit/FirebaseSessionsTests+BaseBehaviors.swift

View workflow job for this annotation

GitHub Actions / spm / spm (macos-15, Xcode_16.3, visionOS)

test_multipleInitiations_logsSessionEventEachInitiation, XCTAssertEqual failed: ("0") is not equal to ("2")
}

#endif // !os(watchOS)
Expand Down
2 changes: 1 addition & 1 deletion FirebaseSessions/Tests/Unit/InitiatorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
26 changes: 2 additions & 24 deletions FirebaseSessions/Tests/Unit/Library/LifecycleNotifications.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on test failure, something else specific to Catalyst might matter?

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)
Expand All @@ -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)
Expand Down
Loading