Skip to content

Commit 39a8b52

Browse files
committed
Test proving OpRepo.enqueue doesn't reset waittime
We want to prevent a misbehaving app stuck in a loop from continuously sending updates every opRepoExecutionInterval (5 seconds currently). By waiting for the dust to settle we ensure the app is done making updates.
1 parent a9dfc09 commit 39a8b52

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,32 @@ class OperationRepoTests : FunSpec({
538538
)
539539
}
540540
}
541+
542+
// We want to prevent a misbehaving app stuck in a loop from continuously
543+
// sending updates every opRepoExecutionInterval (5 seconds currently).
544+
// By waiting for the dust to settle we ensure the app is done making
545+
// updates.
546+
test("ensure each time enqueue is called it restarts the delay time") {
547+
// Given
548+
val mocks = Mocks()
549+
mocks.configModelStore.model.opRepoExecutionInterval = 100
550+
551+
// When
552+
mocks.operationRepo.start()
553+
launch {
554+
repeat(10) {
555+
mocks.operationRepo.enqueue(mockOperation(groupComparisonType = GroupComparisonType.ALTER))
556+
delay(50)
557+
}
558+
}
559+
val result =
560+
withTimeoutOrNull(500) {
561+
mocks.operationRepo.enqueueAndWait(mockOperation(groupComparisonType = GroupComparisonType.ALTER))
562+
}
563+
564+
// Then
565+
result shouldBe null
566+
}
541567
}) {
542568
companion object {
543569
private fun mockOperation(

0 commit comments

Comments
 (0)