Remove hangs (#251)

This commit is contained in:
David Perez 2023-11-16 09:17:55 -06:00 committed by Álison Fernandes
parent 8962f47898
commit f912eb14ef
2 changed files with 4 additions and 31 deletions

View file

@ -22,10 +22,10 @@ import com.x8bit.bitwarden.data.vault.datasource.sdk.model.createMockSdkCipher
import com.x8bit.bitwarden.data.vault.datasource.sdk.model.createMockSdkFolder
import com.x8bit.bitwarden.data.vault.repository.model.VaultData
import com.x8bit.bitwarden.data.vault.repository.model.VaultUnlockResult
import com.x8bit.bitwarden.testingtools.hangs
import com.x8bit.bitwarden.testingtools.just
import io.mockk.awaits
import io.mockk.coEvery
import io.mockk.coVerify
import io.mockk.just
import io.mockk.mockk
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
@ -347,7 +347,7 @@ class VaultRepositoryTest {
organizationKeys = mapOf(),
),
)
} just hangs()
} just awaits
val scope = CoroutineScope(Dispatchers.Unconfined)
scope.launch {
@ -391,7 +391,7 @@ class VaultRepositoryTest {
organizationKeys = mapOf(),
),
)
} just hangs()
} just awaits
val scope = CoroutineScope(Dispatchers.Unconfined)
scope.launch {

View file

@ -1,27 +0,0 @@
package com.x8bit.bitwarden.testingtools
import io.mockk.MockKAdditionalAnswerScope
import io.mockk.MockKStubScope
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.first
/**
* A helper alias for [Hangs] to be consistent with the mockk DSL.
*
* Example: coEvery { service.suspend() } just hangs()
*/
typealias hangs<T> = Hangs<T>
/**
* A class that will hang indefinitely when invoked.
*/
class Hangs<T> {
suspend operator fun invoke(): T = MutableSharedFlow<T>().first()
}
/**
* A coAnswers placeholder for suspending functions that should never return.
*/
suspend infix fun <T, B> MockKStubScope<T, B>.just(
hangs: Hangs<T>,
): MockKAdditionalAnswerScope<T, B> = coAnswers { hangs() }