@@ -5,6 +5,8 @@ import com.onesignal.common.threading.suspendifyOnIO
55import com.onesignal.debug.LogLevel
66import com.onesignal.debug.internal.logging.Logging
77import com.onesignal.mocks.AndroidMockHelper
8+ import com.onesignal.mocks.IOMockHelper
9+ import com.onesignal.mocks.IOMockHelper.awaitIO
810import com.onesignal.mocks.MockHelper
911import com.onesignal.notifications.INotificationReceivedEvent
1012import com.onesignal.notifications.INotificationWillDisplayEvent
@@ -96,6 +98,9 @@ private class Mocks {
9698}
9799
98100class NotificationGenerationProcessorTests : FunSpec ({
101+
102+ listener(IOMockHelper )
103+
99104 beforeAny {
100105 Logging .logLevel = LogLevel .NONE
101106
@@ -276,16 +281,17 @@ class NotificationGenerationProcessorTests : FunSpec({
276281 coEvery { mocks.notificationLifecycleService.externalNotificationWillShowInForeground(any()) } coAnswers {
277282 val willDisplayEvent = firstArg<INotificationWillDisplayEvent >()
278283 willDisplayEvent.preventDefault(false)
284+ // Call preventDefault(true) synchronously to wake the waiter before it times out
285+ willDisplayEvent.preventDefault(true)
286+ // Then call display() asynchronously to ensure it happens after waitForWake completes
279287 suspendifyOnIO {
280- delay(100)
281- willDisplayEvent.preventDefault(true)
282- delay(100)
283288 willDisplayEvent.notification.display()
284289 }
285290 }
286291
287292 // When
288293 mocks.notificationGenerationProcessor.processNotificationData(mocks.context, 1, mocks.notificationPayload, false, 1111)
294+ awaitIO()
289295
290296 // Then
291297 coVerify(exactly = 0) {
@@ -301,15 +307,14 @@ class NotificationGenerationProcessorTests : FunSpec({
301307 val receivedEvent = firstArg<INotificationReceivedEvent >()
302308 receivedEvent.preventDefault(false)
303309 suspendifyOnIO {
304- delay(100)
305310 receivedEvent.preventDefault(true)
306- delay(100)
307311 receivedEvent.notification.display()
308312 }
309313 }
310314
311315 // When
312316 mocks.notificationGenerationProcessor.processNotificationData(mocks.context, 1, mocks.notificationPayload, true, 1111)
317+ awaitIO()
313318
314319 // Then
315320 coVerify(exactly = 0) {
0 commit comments