mirror of
https://github.com/mihonapp/mihon.git
synced 2025-11-15 13:37:29 +01:00
Fix flaky migration tests (#2663)
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
package mihon.core.migration
|
||||
|
||||
import io.kotest.assertions.nondeterministic.eventually
|
||||
import io.mockk.slot
|
||||
import io.mockk.spyk
|
||||
import io.mockk.verify
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.DelicateCoroutinesApi
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.newSingleThreadContext
|
||||
@@ -17,6 +19,7 @@ import org.junit.jupiter.api.Assertions.assertInstanceOf
|
||||
import org.junit.jupiter.api.BeforeAll
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.junit.jupiter.api.Test
|
||||
import kotlin.time.Duration.Companion.seconds
|
||||
|
||||
class MigratorTest {
|
||||
|
||||
@@ -26,7 +29,7 @@ class MigratorTest {
|
||||
lateinit var migrationStrategyFactory: MigrationStrategyFactory
|
||||
|
||||
@BeforeEach
|
||||
fun initilize() {
|
||||
fun initialize() {
|
||||
migrationContext = MigrationContext(false)
|
||||
migrationJobFactory = spyk(MigrationJobFactory(migrationContext, CoroutineScope(Dispatchers.Main + Job())))
|
||||
migrationCompletedListener = spyk<MigrationCompletedListener>(block = {})
|
||||
@@ -45,7 +48,7 @@ class MigratorTest {
|
||||
|
||||
verify { migrationJobFactory.create(capture(migrations)) }
|
||||
assertEquals(1, migrations.captured.size)
|
||||
verify { migrationCompletedListener() }
|
||||
eventually(2.seconds) { verify { migrationCompletedListener() } }
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -86,7 +89,7 @@ class MigratorTest {
|
||||
|
||||
verify { migrationJobFactory.create(capture(migrations)) }
|
||||
assertEquals(2, migrations.captured.size)
|
||||
verify { migrationCompletedListener() }
|
||||
eventually(2.seconds) { verify { migrationCompletedListener() } }
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -114,7 +117,7 @@ class MigratorTest {
|
||||
|
||||
verify { migrationJobFactory.create(capture(migrations)) }
|
||||
assertEquals(10, migrations.captured.size)
|
||||
verify { migrationCompletedListener() }
|
||||
eventually(2.seconds) { verify { migrationCompletedListener() } }
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -135,11 +138,12 @@ class MigratorTest {
|
||||
|
||||
verify { migrationJobFactory.create(capture(migrations)) }
|
||||
assertEquals(2, migrations.captured.size)
|
||||
verify { migrationCompletedListener() }
|
||||
eventually(2.seconds) { verify { migrationCompletedListener() } }
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
@OptIn(DelicateCoroutinesApi::class)
|
||||
val mainThreadSurrogate = newSingleThreadContext("UI thread")
|
||||
|
||||
@BeforeAll
|
||||
|
||||
Reference in New Issue
Block a user