Skip to content

Commit 8001c6e

Browse files
committed
add results from executeOperations test
1 parent c5fde00 commit 8001c6e

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import com.onesignal.common.threading.Waiter
44
import com.onesignal.common.threading.WaiterWithValue
55
import com.onesignal.core.internal.operations.impl.OperationModelStore
66
import com.onesignal.core.internal.operations.impl.OperationRepo
7+
import com.onesignal.core.internal.operations.impl.OperationRepo.OperationQueueItem
78
import com.onesignal.core.internal.time.impl.Time
89
import com.onesignal.debug.LogLevel
910
import com.onesignal.debug.internal.logging.Logging
@@ -453,6 +454,37 @@ class OperationRepoTests : FunSpec({
453454
immediateResult shouldBe null
454455
delayedResult shouldBe true
455456
}
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+
}
456488
}) {
457489
companion object {
458490
private fun mockOperation(

0 commit comments

Comments
 (0)