Skip to content

Commit 4580941

Browse files
committed
fix: add a waiter for OSPrimaryMainScope to wait for operation enqueue
1 parent dbe3fa7 commit 4580941

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

OneSignalSDK/onesignal/core/src/main/java/com/onesignal/common/threading/OSPrimaryCoroutineScope.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,6 @@ object OSPrimaryCoroutineScope {
1616
block()
1717
}
1818
}
19+
20+
suspend fun waitForIdle() = mainScope.launch { }.join()
1921
}

OneSignalSDK/onesignal/core/src/test/java/com/onesignal/core/internal/operations/OperationRepoTests.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.onesignal.core.internal.operations
22

3+
import com.onesignal.common.threading.OSPrimaryCoroutineScope
34
import com.onesignal.common.threading.Waiter
45
import com.onesignal.common.threading.WaiterWithValue
56
import com.onesignal.core.internal.operations.impl.OperationModelStore
@@ -100,6 +101,7 @@ class OperationRepoTests : FunSpec({
100101
listOf(mocks.executor),
101102
operationModelStore,
102103
mocks.configModelStore,
104+
mocks.identityModelStore,
103105
Time(),
104106
getNewRecordState(mocks.configModelStore),
105107
),
@@ -165,6 +167,7 @@ class OperationRepoTests : FunSpec({
165167
// When
166168
operationRepo.start()
167169
operationRepo.enqueue(MyOperation())
170+
OSPrimaryCoroutineScope.waitForIdle()
168171

169172
// Then
170173
operationRepo.containsInstanceOf<MyOperation>() shouldBe true
@@ -269,6 +272,7 @@ class OperationRepoTests : FunSpec({
269272
// When
270273
opRepo.start()
271274
opRepo.enqueue(mockOperation())
275+
OSPrimaryCoroutineScope.waitForIdle()
272276
val response1 =
273277
withTimeoutOrNull(999) {
274278
opRepo.enqueueAndWait(mockOperation())
@@ -647,6 +651,7 @@ class OperationRepoTests : FunSpec({
647651
mocks.operationRepo.start()
648652
mocks.operationRepo.enqueue(operation1)
649653
mocks.operationRepo.enqueue(operation2)
654+
OSPrimaryCoroutineScope.waitForIdle()
650655
mocks.operationRepo.enqueueAndWait(operation3)
651656

652657
// Then
@@ -727,6 +732,7 @@ class OperationRepoTests : FunSpec({
727732
val mocks = Mocks()
728733
val op = mockOperation()
729734
mocks.operationRepo.enqueue(op)
735+
OSPrimaryCoroutineScope.waitForIdle()
730736

731737
// When
732738
mocks.operationRepo.loadSavedOperations()
@@ -767,6 +773,7 @@ class OperationRepoTests : FunSpec({
767773
// When
768774
opRepo.start()
769775
opRepo.enqueue(mockOperation())
776+
OSPrimaryCoroutineScope.waitForIdle()
770777
val response1 =
771778
withTimeoutOrNull(999) {
772779
opRepo.enqueueAndWait(mockOperation())

0 commit comments

Comments
 (0)