Skip to content

Commit 1b4c0b2

Browse files
author
AR Abdul Azeez
committed
fix(test): stabilize prevent-default-twice notification generation tests
Remove notification.display() after the second preventDefault(true). The display waiter uses a CONFLATED channel; display() wakes with true and overwrites preventDefault(true)'s wake(false), so the processor could still call displayNotification — flaky on fast CI (see PR #2605). Clarify IOMockHelper KDoc: top-level launchOnIO is not stubbed; only OneSignalDispatchers.launchOnIO is. Made-with: Cursor
1 parent f1a719d commit 1b4c0b2

2 files changed

Lines changed: 4 additions & 3 deletions

File tree

OneSignalSDK/onesignal/notifications/src/test/java/com/onesignal/notifications/internal/generation/NotificationGenerationProcessorTests.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,9 @@ class NotificationGenerationProcessorTests : FunSpec({
288288
val willDisplayEvent = firstArg<INotificationWillDisplayEvent>()
289289
willDisplayEvent.preventDefault(false)
290290
suspendifyOnIO {
291+
// Second preventDefault(true) wakes the waiter with false; avoid notification.display()
292+
// which would wake(true) and overwrite the conflated channel (CI flake on fast runners).
291293
willDisplayEvent.preventDefault(true)
292-
willDisplayEvent.notification.display()
293294
}
294295
}
295296

@@ -311,7 +312,6 @@ class NotificationGenerationProcessorTests : FunSpec({
311312
receivedEvent.preventDefault(false)
312313
suspendifyOnIO {
313314
receivedEvent.preventDefault(true)
314-
receivedEvent.notification.display()
315315
}
316316
}
317317

OneSignalSDK/onesignal/testhelpers/src/main/java/com/onesignal/mocks/IOMockHelper.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ import java.util.concurrent.atomic.AtomicInteger
3131
* (e.g., delay(50)) to wait for async work to finish.
3232
*
3333
* This helper avoids that by:
34-
* - Mocking `suspendifyOnIO`, `launchOnIO`, and `launchOnDefault` so their blocks run immediately
34+
* - Mocking `suspendifyOnIO`, `suspendifyOnMain`, and `OneSignalDispatchers.launchOnIO` /
35+
* `launchOnDefault` so their blocks run immediately
3536
* - Completing a `CompletableDeferred` when the async block finishes
3637
* - Providing `awaitIO()` so tests can explicitly wait for all async work without sleeps
3738
*

0 commit comments

Comments
 (0)