Skip to content

Commit

Permalink
test: add 'times' parameter to runTest
Browse files Browse the repository at this point in the history
useful for diagnostics
  • Loading branch information
david-allison authored and BrayanDSO committed Jan 2, 2024
1 parent 9d212a4 commit 1d1aa78
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions AnkiDroid/src/test/java/com/ichi2/testutils/TestClass.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import kotlinx.coroutines.test.TestScope
import kotlinx.coroutines.test.UnconfinedTestDispatcher
import kotlinx.coroutines.test.setMain
import net.ankiweb.rsdroid.exceptions.BackendDeckIsFilteredException
import timber.log.Timber
import kotlin.coroutines.CoroutineContext
import kotlin.coroutines.EmptyCoroutineContext
import kotlin.time.Duration.Companion.milliseconds
Expand Down Expand Up @@ -175,12 +176,16 @@ interface TestClass {
fun runTest(
context: CoroutineContext = EmptyCoroutineContext,
dispatchTimeoutMs: Long = 60_000L,
times: Int = 1,
testBody: suspend TestScope.() -> Unit
) {
Dispatchers.setMain(UnconfinedTestDispatcher())
kotlinx.coroutines.test.runTest(context, dispatchTimeoutMs.milliseconds) {
CollectionManager.setTestDispatcher(UnconfinedTestDispatcher(testScheduler))
testBody()
repeat(times) {
if (times != 1) Timber.d("------ Executing test $it/$times ------")
kotlinx.coroutines.test.runTest(context, dispatchTimeoutMs.milliseconds) {
CollectionManager.setTestDispatcher(UnconfinedTestDispatcher(testScheduler))
testBody()
}
}
}
}

0 comments on commit 1d1aa78

Please sign in to comment.