Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Tests] Fix flaky tests 2024/05/09 #2083

Merged
merged 3 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
jinliu9508 marked this conversation as resolved.
Show resolved Hide resolved
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()
jinliu9508 marked this conversation as resolved.
Show resolved Hide resolved
// Waiting here ensures recovery.onOperationRepoLoaded() is called consistently
waiter.waitForWake()

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