Skip to content

Commit

Permalink
Merge pull request #2083 from OneSignal/tests/fix-flaky-tests-2024-05-09
Browse files Browse the repository at this point in the history
[Tests] Fix flaky tests 2024/05/09
  • Loading branch information
jkasten2 authored May 10, 2024
2 parents 6a6dbc2 + 939a164 commit 21eb136
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ class HttpClientTests : FunSpec({

mocks.factory.mockResponse = mockSuccessfulResponse
val response2 =
withTimeoutOrNull(999) {
withTimeoutOrNull(975) {
mocks.httpClient.post("URL", JSONObject())
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,8 @@ class OperationRepoTests : FunSpec({
// When
mocks.operationRepo.addOperationLoadedListener(spyListener)
mocks.operationRepo.start()
// enqueueAndWait used to know we are fully loaded.
mocks.operationRepo.enqueueAndWait(mockOperation())

// Then
mocks.operationRepo.hasSubscribers shouldBe true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.onesignal.user.internal.migrations

import com.onesignal.common.threading.Waiter
import com.onesignal.core.internal.config.ConfigModelStore
import com.onesignal.core.internal.operations.IOperationRepoLoadedListener
import com.onesignal.core.internal.operations.impl.OperationModelStore
import com.onesignal.core.internal.operations.impl.OperationRepo
import com.onesignal.core.internal.time.impl.Time
Expand Down Expand Up @@ -31,16 +33,24 @@ class RecoverFromDroppedLoginBugTests : FunSpec({
)
every { mockOperationModelStore.loadOperations() } just runs
every { mockOperationModelStore.list() } returns listOf()

val recovery = RecoverFromDroppedLoginBug(operationRepo, MockHelper.identityModelStore(), mockConfigModelStore)
every { recovery.onOperationRepoLoaded() } just runs
val recovery = spyk(RecoverFromDroppedLoginBug(operationRepo, MockHelper.identityModelStore(), mockConfigModelStore))

// When
operationRepo.start()
recovery.start()
val waiter = Waiter()
operationRepo.addOperationLoadedListener(
object : IOperationRepoLoadedListener {
override fun onOperationRepoLoaded() {
waiter.wake()
}
},
)
operationRepo.start()
// Waiting here ensures recovery.onOperationRepoLoaded() is called consistently
waiter.waitForWake()

// Then
verify {
verify(exactly = 1) {
operationRepo.subscribe(recovery)
recovery.onOperationRepoLoaded()
}
Expand Down

0 comments on commit 21eb136

Please sign in to comment.