Skip to content

Bug 2004094 - PingUploadScheduler does not correctly end background tasks#3347

Merged
badboy merged 4 commits intomozilla:mainfrom
ih-codes:Bug2004094
Dec 8, 2025
Merged

Bug 2004094 - PingUploadScheduler does not correctly end background tasks#3347
badboy merged 4 commits intomozilla:mainfrom
ih-codes:Bug2004094

Conversation

@ih-codes
Copy link
Copy Markdown
Contributor

@ih-codes ih-codes commented Dec 4, 2025

Bugzilla

  • Fix strict concurrency warnings in Dispatchers by making the type Sendable.
    • You only see these warnings on Swift 6 or on Swift 5 with the SWIFT_STRICT_CONCURRENCY = complete.
    • There are a number of other such warnings in the project but I didn't want to start changing a bunch of other files on this PR
  • Fix bug in PingUploadScheduler for breaking out of while-switch and continuing execution to the background task handling.
  • Make PingUploadScheduler more testable with dependency injection via protocols.
  • Add unit tests for PingUploadScheduler.
  • Add mock types for testing.

I wanted to be a good citizen and test this thoroughly since I'm not sure how to check this against my local iOS build, but if you are not happy with all the dependency injection changes that let me use mocks, I can back out those changes.

@ih-codes ih-codes requested a review from a team as a code owner December 4, 2025 21:36
@ih-codes ih-codes requested review from badboy and removed request for a team December 4, 2025 21:36
@ih-codes
Copy link
Copy Markdown
Contributor Author

ih-codes commented Dec 4, 2025

cc @travis79

@ih-codes ih-codes changed the title Bug 2004094 - PingUploadScheduler.swift does not correctly end background tasks Bug 2004094 - PingUploadScheduler does not correctly end background tasks Dec 4, 2025
Copy link
Copy Markdown
Member

@badboy badboy left a comment

Choose a reason for hiding this comment

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

I would have prefered to split out the first two commits, as they are unrelated. But it's fine now.

Tests are failing unfortunately.

/Users/distiller/project/glean-core/ios/Glean/Net/BackgroundTaskScheduler.swift:16:1: warning: extension declares a conformance of imported type 'UIApplication' to imported protocol 'Sendable'; this will not behave correctly if the owners of 'UIKit' introduce this conformance in the future
extension UIApplication: BackgroundTaskScheduler {}
^
/Users/distiller/project/glean-core/ios/Glean/Net/BackgroundTaskScheduler.swift:16:1: note: add '@retroactive' to silence this warning
extension UIApplication: BackgroundTaskScheduler {}
^
/Users/distiller/project/glean-core/ios/Glean/Net/BackgroundTaskScheduler.swift:16:1: error: type 'UIApplication' does not conform to protocol 'BackgroundTaskScheduler'
extension UIApplication: BackgroundTaskScheduler {}
^
UIKit.UIApplication.beginBackgroundTask:3:25: note: candidate has non-matching type '(String?, (@Sendable () -> Void)?) -> UIBackgroundTaskIdentifier'
  nonisolated open func beginBackgroundTask(withName taskName: String?, expirationHandler handler: (@Sendable () -> Void)? = nil) -> UIBackgroundTaskIdentifier}

I'm not the biggest fan of all that mocking and protocols. But I can see the value of testing the scheduler that way, so we can take it.

Can you squash the cleanup commits ("Add some documentation / cleanup.", "Remove unneeded throws. Swiftlint fixes.") into their respective commits?

@ih-codes
Copy link
Copy Markdown
Contributor Author

ih-codes commented Dec 5, 2025

Thanks @badboy! Regarding the test warnings, I understand why I wasn't seeing those locally. It's an Xcode version mismatch. You might want to look into updating your pipeline from Xcode 16.4 to Xcode 26.

There were some significant strict concurrency changes between both versions (on the iOS side, we saw for a while warnings/errors in Xcode 16 that weren't in Xcode 26, and vice versa). The iOS team actually skipped 16.4 (stayed on 16.2) because of some additional issues with 16.4.

I will look to see if I can resolve these without being able to reproduce them locally (since I don't have 16.4 and my internet is incredibly slow!). But, if I can't easily do that I'll just split my PR up into a fix and do minimal strict concurrency adjustments even if they will become warnings in Xcode 26.

Comment thread glean-core/ios/Glean/Dispatchers.swift Outdated
@badboy
Copy link
Copy Markdown
Member

badboy commented Dec 8, 2025

#3350 landed, updating to Xcode 26.2 -- that should probably fix the test failure here.

@badboy badboy enabled auto-merge (rebase) December 8, 2025 16:28
@badboy badboy merged commit 76e2037 into mozilla:main Dec 8, 2025
30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants