Skip to content

Commit 9f8afc0

Browse files
committed
stall OperationRepo by opRepoPostCreateDelay
The OperationRepo can't juggle two different users correctly, so stall the whole queue by opRepoPostCreateDelay. We plan to address this limitation in a future PR.
1 parent 5d5c837 commit 9f8afc0

File tree

2 files changed

+17
-44
lines changed

2 files changed

+17
-44
lines changed

OneSignalSDK/onesignal/core/src/main/java/com/onesignal/core/internal/operations/impl/OperationRepo.kt

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -235,12 +235,17 @@ internal class OperationRepo(
235235
queue.forEach { it.operation.translateIds(response.idTranslations) }
236236
}
237237
response.idTranslations.values.forEach { _newRecordState.add(it) }
238-
coroutineScope.launch {
239-
val waitTime = _configModelStore.model.opRepoPostCreateDelay
240-
delay(waitTime)
241-
synchronized(queue) {
242-
if (queue.isNotEmpty()) waiter.wake(LoopWaiterMessage(false, waitTime))
243-
}
238+
// Stall processing the queue so the backend's DB has to time
239+
// reflect the change before we do any other operations to it.
240+
// NOTE: Future: We could run this logic in a
241+
// coroutineScope.launch() block so other operations not
242+
// effecting this these id's can still be done in parallel,
243+
// however other parts of the system don't currently account
244+
// for this so this is not safe to do.
245+
val waitTime = _configModelStore.model.opRepoPostCreateDelay
246+
delay(waitTime)
247+
synchronized(queue) {
248+
if (queue.isNotEmpty()) waiter.wake(LoopWaiterMessage(false, waitTime))
244249
}
245250
}
246251

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

Lines changed: 6 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -546,31 +546,15 @@ class OperationRepoTests : FunSpec({
546546
mocks.operationRepo.start()
547547
mocks.operationRepo.enqueue(operation1)
548548
val job = launch { mocks.operationRepo.enqueueAndWait(operation2) }.also { yield() }
549-
mocks.operationRepo.enqueue(operation3)
549+
mocks.operationRepo.enqueueAndWait(operation3)
550550
job.join()
551551

552552
// Then
553553
coVerifyOrder {
554-
mocks.executor.execute(
555-
withArg {
556-
it.count() shouldBe 1
557-
it[0] shouldBe operation1
558-
},
559-
)
554+
mocks.executor.execute(listOf(operation1))
560555
operation2.translateIds(mapOf("local-id1" to "id2"))
561-
mocks.executor.execute(
562-
withArg {
563-
it.count() shouldBe 1
564-
it[0] shouldBe operation3
565-
},
566-
)
567-
// Ensure operation2 runs after operation3 as it has to wait for the create delay
568-
mocks.executor.execute(
569-
withArg {
570-
it.count() shouldBe 1
571-
it[0] shouldBe operation2
572-
},
573-
)
556+
mocks.executor.execute(listOf(operation2))
557+
mocks.executor.execute(listOf(operation3))
574558
}
575559
}
576560

@@ -595,25 +579,9 @@ class OperationRepoTests : FunSpec({
595579

596580
// Then
597581
coVerifyOrder {
598-
mocks.executor.execute(
599-
withArg {
600-
it.count() shouldBe 1
601-
it[0] shouldBe operation1
602-
},
603-
)
582+
mocks.executor.execute(listOf(operation1))
604583
operation2.translateIds(mapOf("local-id1" to "id2"))
605-
mocks.executor.execute(
606-
withArg {
607-
it.count() shouldBe 1
608-
it[0] shouldBe operation2
609-
},
610-
)
611-
mocks.executor.execute(
612-
withArg {
613-
it.count() shouldBe 1
614-
it[0] shouldBe operation3
615-
},
616-
)
584+
mocks.executor.execute(listOf(operation2, operation3))
617585
}
618586
}
619587

0 commit comments

Comments
 (0)