mirror of
https://github.com/block/buzz.git
synced 2026-11-02 15:31:27 +00:00
fix(push-demo): return notification completion on main thread
Signed-off-by: Tom Brow <tomb@block.xyz>
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user