@@ -4,6 +4,7 @@ import com.onesignal.common.threading.Waiter
4
4
import com.onesignal.common.threading.WaiterWithValue
5
5
import com.onesignal.core.internal.operations.impl.OperationModelStore
6
6
import com.onesignal.core.internal.operations.impl.OperationRepo
7
+ import com.onesignal.core.internal.operations.impl.OperationRepo.OperationQueueItem
7
8
import com.onesignal.core.internal.time.impl.Time
8
9
import com.onesignal.debug.LogLevel
9
10
import com.onesignal.debug.internal.logging.Logging
@@ -453,6 +454,37 @@ class OperationRepoTests : FunSpec({
453
454
immediateResult shouldBe null
454
455
delayedResult shouldBe true
455
456
}
457
+
458
+ test("ensure results from executeOperations are added to beginning of the queue") {
459
+ // Given
460
+ val mocks = Mocks ()
461
+ val executor = mocks.executor
462
+ val opWithResult = mockOperationNonGroupable()
463
+ val opFromResult = mockOperationNonGroupable()
464
+ coEvery {
465
+ executor.execute(listOf(opWithResult))
466
+ } coAnswers {
467
+ ExecutionResponse (ExecutionResult .SUCCESS , operations = listOf(opFromResult))
468
+ }
469
+ val firstOp = mockOperationNonGroupable()
470
+ val secondOp = mockOperationNonGroupable()
471
+
472
+ // When
473
+ mocks.operationRepo.start()
474
+ mocks.operationRepo.enqueue(firstOp)
475
+ mocks.operationRepo.executeOperations(
476
+ listOf(OperationQueueItem (opWithResult, bucket = 0)),
477
+ )
478
+ mocks.operationRepo.enqueueAndWait(secondOp)
479
+
480
+ // Then
481
+ coVerifyOrder {
482
+ executor.execute(withArg { it[0] shouldBe opWithResult })
483
+ executor.execute(withArg { it[0] shouldBe opFromResult })
484
+ executor.execute(withArg { it[0] shouldBe firstOp })
485
+ executor.execute(withArg { it[0] shouldBe secondOp })
486
+ }
487
+ }
456
488
}) {
457
489
companion object {
458
490
private fun mockOperation (
0 commit comments