Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,6 @@ class CompletionAwaiterTests : FunSpec({
jobs.add(thread)
}

// Wait a bit to ensure all threads are waiting
Thread.sleep(100)

// Complete the awaiter
awaiter.complete()

Expand Down Expand Up @@ -257,9 +254,6 @@ class CompletionAwaiterTests : FunSpec({
}
blockingThreads.forEach { it.start() }

// Wait a bit to ensure all are waiting
Thread.sleep(100)

// Complete the awaiter
awaiter.complete()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,19 @@ import com.onesignal.common.threading.suspendifyOnIO
import com.onesignal.core.internal.application.impl.ApplicationService
import com.onesignal.debug.LogLevel
import com.onesignal.debug.internal.logging.Logging
import com.onesignal.mocks.IOMockHelper
import com.onesignal.mocks.IOMockHelper.awaitIO
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.shouldBe
import io.mockk.spyk
import io.mockk.verify
import kotlinx.coroutines.delay
import org.robolectric.Robolectric

@RobolectricTest
class ApplicationServiceTests : FunSpec({

listener(IOMockHelper)

beforeAny {
Logging.logLevel = LogLevel.NONE
}
Expand Down Expand Up @@ -199,7 +202,7 @@ class ApplicationServiceTests : FunSpec({
waiter.wake(response)
}

delay(7000)
awaitIO(7_000)

applicationService.onActivityStarted(activity)
val response = waiter.waitForWake()
Expand All @@ -224,8 +227,6 @@ class ApplicationServiceTests : FunSpec({
waiter.wake(response)
}

delay(3000)

applicationService.onActivityStarted(activity)
val response = waiter.waitForWake()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ class StartupServiceTests : FunSpec({

// When
startupService.scheduleStart()
awaitIO()

// Then
Thread.sleep(10)
verify(exactly = 1) { mockStartupService1.start() }
verify(exactly = 1) { mockStartupService2.start() }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import com.onesignal.common.exceptions.BackendException
import com.onesignal.common.threading.Waiter
import com.onesignal.debug.LogLevel
import com.onesignal.debug.internal.logging.Logging
import com.onesignal.mocks.IOMockHelper
import com.onesignal.mocks.IOMockHelper.awaitIO
import com.onesignal.mocks.MockHelper
import com.onesignal.session.internal.influence.IInfluenceManager
import com.onesignal.session.internal.influence.Influence
Expand Down Expand Up @@ -32,10 +34,12 @@ import io.mockk.just
import io.mockk.mockk
import io.mockk.runs
import io.mockk.spyk
import kotlinx.coroutines.delay
import org.json.JSONArray

class OutcomeEventsControllerTests : FunSpec({

listener(IOMockHelper)

beforeAny {
Logging.logLevel = LogLevel.NONE
}
Expand Down Expand Up @@ -595,7 +599,7 @@ class OutcomeEventsControllerTests : FunSpec({
// When
outcomeEventsController.start()

delay(1000)
awaitIO()

// Then
coVerify(exactly = 1) {
Expand Down Expand Up @@ -687,7 +691,7 @@ class OutcomeEventsControllerTests : FunSpec({
// When
outcomeEventsController.start()

delay(1000)
awaitIO()

// Then
coVerify(exactly = 1) {
Expand Down Expand Up @@ -763,7 +767,7 @@ class OutcomeEventsControllerTests : FunSpec({

// When
outcomeEventsController.start()
delay(1000)
awaitIO()

// Then
coVerify(exactly = 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import com.onesignal.core.internal.operations.impl.OperationRepo
import com.onesignal.core.internal.time.impl.Time
import com.onesignal.debug.LogLevel
import com.onesignal.debug.internal.logging.Logging
import com.onesignal.mocks.IOMockHelper
import com.onesignal.mocks.IOMockHelper.awaitIO
import com.onesignal.mocks.MockHelper
import com.onesignal.user.internal.operations.ExecutorMocks
import com.onesignal.user.internal.operations.LoginUserOperation
Expand All @@ -16,7 +18,6 @@ import io.mockk.mockk
import io.mockk.runs
import io.mockk.spyk
import io.mockk.verify
import kotlinx.coroutines.delay
import kotlinx.coroutines.withTimeout

private class Mocks {
Expand Down Expand Up @@ -76,6 +77,9 @@ private class Mocks {
}

class RecoverFromDroppedLoginBugTests : FunSpec({

listener(IOMockHelper)

beforeAny {
Logging.logLevel = LogLevel.NONE
}
Expand All @@ -100,7 +104,7 @@ class RecoverFromDroppedLoginBugTests : FunSpec({
// When
mocks.operationRepo.start()
// give operation repo some time to fully initialize
delay(200)
awaitIO()

mocks.recovery.start()
withTimeout(1_000) { mocks.operationRepo.awaitInitialized() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import com.onesignal.common.threading.suspendifyOnIO
import com.onesignal.debug.LogLevel
import com.onesignal.debug.internal.logging.Logging
import com.onesignal.mocks.AndroidMockHelper
import com.onesignal.mocks.IOMockHelper
import com.onesignal.mocks.IOMockHelper.awaitIO
import com.onesignal.mocks.MockHelper
import com.onesignal.notifications.INotificationReceivedEvent
import com.onesignal.notifications.INotificationWillDisplayEvent
Expand Down Expand Up @@ -96,6 +98,9 @@ private class Mocks {
}

class NotificationGenerationProcessorTests : FunSpec({

listener(IOMockHelper)

beforeAny {
Logging.logLevel = LogLevel.NONE

Expand Down Expand Up @@ -276,16 +281,17 @@ class NotificationGenerationProcessorTests : FunSpec({
coEvery { mocks.notificationLifecycleService.externalNotificationWillShowInForeground(any()) } coAnswers {
val willDisplayEvent = firstArg<INotificationWillDisplayEvent>()
willDisplayEvent.preventDefault(false)
// Call preventDefault(true) synchronously to wake the waiter before it times out
willDisplayEvent.preventDefault(true)
// Then call display() asynchronously to ensure it happens after waitForWake completes
suspendifyOnIO {
delay(100)
willDisplayEvent.preventDefault(true)
delay(100)
willDisplayEvent.notification.display()
}
}

// When
mocks.notificationGenerationProcessor.processNotificationData(mocks.context, 1, mocks.notificationPayload, false, 1111)
awaitIO()

// Then
coVerify(exactly = 0) {
Expand All @@ -301,15 +307,14 @@ class NotificationGenerationProcessorTests : FunSpec({
val receivedEvent = firstArg<INotificationReceivedEvent>()
receivedEvent.preventDefault(false)
suspendifyOnIO {
delay(100)
receivedEvent.preventDefault(true)
delay(100)
receivedEvent.notification.display()
}
}

// When
mocks.notificationGenerationProcessor.processNotificationData(mocks.context, 1, mocks.notificationPayload, true, 1111)
awaitIO()

// Then
coVerify(exactly = 0) {
Expand Down
Loading