fix(push-demo): return notification completion on main thread

Signed-off-by: Tom Brow <tomb@block.xyz>
This commit is contained in:
Tom Brow
2026-08-26 11:11:53 -07:00
parent fb9c81b896
commit c524862c05
2 changed files with 26 additions and 1 deletions

View File

@@ -16,7 +16,14 @@ final class BuzzOneShotCompletion {
let completion = completion
self.completion = nil
lock.unlock()
completion?()
guard let completion else { return }
if Thread.isMainThread {
completion()
} else {
// Reply publication finishes on a URLSession callback queue, while the
// notification response completion crosses back into UIKit.
DispatchQueue.main.async(execute: completion)
}
}
}

View File

@@ -217,6 +217,24 @@ final class BuzzPushSnapshotEnrichmentTests: XCTestCase {
}
final class BuzzPushNotificationResponseTests: XCTestCase {
func testBackgroundCompletionReturnsToMainThreadExactlyOnce() {
let completed = expectation(description: "completion returned on main thread")
var completionCount = 0
let completion = BuzzOneShotCompletion {
XCTAssertTrue(Thread.isMainThread)
completionCount += 1
completed.fulfill()
}
DispatchQueue.global().async {
completion.call()
completion.call()
}
wait(for: [completed], timeout: 1)
XCTAssertEqual(completionCount, 1)
}
func testValidReminderActionRoutesContextWithoutOpeningFlutter() {
let context = BuzzPushReplyContext(
eventID: "message-id",