Warmup molecule only once.

This commit is contained in:
Marco Romano 2023-09-13 15:42:48 +02:00
parent b860bd30bd
commit 5d8666a507

View file

@ -32,17 +32,22 @@ import kotlin.time.Duration.Companion.seconds
* Applying this test rule ensures that the slow initialisation is not done * Applying this test rule ensures that the slow initialisation is not done
* inside runTest which has a short default timeout. * inside runTest which has a short default timeout.
*/ */
class WarmUpRule: TestRule { class WarmUpRule : TestRule {
override fun apply(base: Statement, description: Description): Statement = object: Statement() { companion object {
override fun evaluate() { init {
runTest(timeout = 60.seconds) { warmUpMolecule()
moleculeFlow(RecompositionMode.Immediate) { }
// Do nothing }
}.test {
awaitItem() // Await a Unit composition override fun apply(base: Statement, description: Description): Statement = base
} }
}
base.evaluate() private fun warmUpMolecule() {
runTest(timeout = 60.seconds) {
moleculeFlow(RecompositionMode.Immediate) {
// Do nothing
}.test {
awaitItem() // Await a Unit composition
} }
} }
} }