Skip to content

Commit fa4c20a

Browse files
committed
Fix: flaky test unit caused by enqueue not complete instantly
1 parent aaf6693 commit fa4c20a

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,12 @@ class OperationRepoTests : FunSpec({
157157
// When
158158
operationRepo.start()
159159
operationRepo.enqueue(MyOperation())
160+
// Wait for the background coroutine to complete enqueue
161+
withTimeout(1000) {
162+
while (operationRepo.queue.size == 0) {
163+
delay(10)
164+
}
165+
}
160166

161167
// Then
162168
operationRepo.containsInstanceOf<MyOperation>() shouldBe true
@@ -609,6 +615,12 @@ class OperationRepoTests : FunSpec({
609615
// When
610616
mocks.operationRepo.start()
611617
mocks.operationRepo.enqueue(operation1)
618+
// Wait for the background coroutine to complete enqueue
619+
withTimeout(1000) {
620+
while (mocks.operationRepo.queue.size == 0) {
621+
delay(10)
622+
}
623+
}
612624
val job = launch { mocks.operationRepo.enqueueAndWait(operation2) }.also { yield() }
613625
mocks.operationRepo.enqueueAndWait(operation3)
614626
job.join()
@@ -639,6 +651,12 @@ class OperationRepoTests : FunSpec({
639651
mocks.operationRepo.start()
640652
mocks.operationRepo.enqueue(operation1)
641653
mocks.operationRepo.enqueue(operation2)
654+
// Wait for the background coroutine to complete enqueue
655+
withTimeout(1000) {
656+
while (mocks.operationRepo.queue.size < 2) {
657+
delay(10)
658+
}
659+
}
642660
mocks.operationRepo.enqueueAndWait(operation3)
643661

644662
// Then

0 commit comments

Comments
 (0)