Skip to content

Commit 5f9c785

Browse files
committed
replace runCurrent with delay() in tests
see Kotlin/kotlinx.coroutines#3919
1 parent 8c08e80 commit 5f9c785

File tree

3 files changed

+10
-12
lines changed

3 files changed

+10
-12
lines changed

kmposable-core/src/commonTest/kotlin/com/labosu/kmposable/ScopedActionTests.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import app.cash.turbine.test
66
import kotlinx.coroutines.ExperimentalCoroutinesApi
77
import kotlinx.coroutines.FlowPreview
88
import kotlinx.coroutines.cancel
9+
import kotlinx.coroutines.delay
910
import kotlinx.coroutines.test.StandardTestDispatcher
1011
import kotlinx.coroutines.test.TestScope
11-
import kotlinx.coroutines.test.runCurrent
1212
import kotlinx.coroutines.test.runTest
1313
import kotlin.test.BeforeTest
1414
import kotlin.test.Test
@@ -35,7 +35,7 @@ class ScopedActionTests : StoreCoroutineTest() {
3535
val effectScope = TestScope(StandardTestDispatcher())
3636
assertEquals("", awaitItem().testProperty)
3737
testStore.send(TestAction.LongRunningScopedEffectAction(effectScope))
38-
testCoroutineScope.runCurrent()
38+
delay(1)
3939

4040
//the value should increment by 1
4141
var property = awaitItem().testProperty.toInt()

kmposable-core/src/commonTest/kotlin/com/labosu/kmposable/StoreExceptionHandlingTests.kt

+5-7
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ package com.labosu.kmposable
44

55
import com.labosu.kmposable.internal.MutableStateFlowStore
66
import kotlinx.coroutines.ExperimentalCoroutinesApi
7-
import kotlinx.coroutines.test.runCurrent
7+
import kotlinx.coroutines.delay
88
import kotlinx.coroutines.test.runTest
99
import kotlin.test.BeforeTest
1010
import kotlin.test.Test
@@ -26,9 +26,8 @@ class StoreExceptionHandlingTests : StoreCoroutineTest() {
2626
fun `reduce exception should be handled`() {
2727
assertFailsWith<MutableStateFlowStore.Companion.ReducerException> {
2828
testCoroutineScope.runTest {
29-
testStore.send(TestAction.ThrowExceptionAction).also {
30-
testCoroutineScope.runCurrent()
31-
}
29+
testStore.send(TestAction.ThrowExceptionAction)
30+
delay(1)
3231
}
3332
}
3433
}
@@ -37,9 +36,8 @@ class StoreExceptionHandlingTests : StoreCoroutineTest() {
3736
fun `effect exception should be handled`() {
3837
assertFailsWith<MutableStateFlowStore.Companion.EffectException> {
3938
testCoroutineScope.runTest {
40-
testStore.send(TestAction.StartExceptionThrowingEffectAction).also {
41-
testCoroutineScope.runCurrent()
42-
}
39+
testStore.send(TestAction.StartExceptionThrowingEffectAction)
40+
delay(1)
4341
}
4442
}
4543
}

kmposable-core/src/commonTest/kotlin/com/labosu/kmposable/StoreReducerTests.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
package com.labosu.kmposable
44

55
import kotlinx.coroutines.ExperimentalCoroutinesApi
6-
import kotlinx.coroutines.test.runCurrent
6+
import kotlinx.coroutines.delay
77
import kotlinx.coroutines.test.runTest
88
import kotlin.test.BeforeTest
99
import kotlin.test.Test
@@ -26,7 +26,7 @@ class StoreReducerTests : StoreCoroutineTest() {
2626
@Test
2727
fun `reducer should be called exactly once if one action is sent`() = testCoroutineScope.runTest {
2828
testStore.send(TestAction.DoNothingAction)
29-
testCoroutineScope.runCurrent()
29+
delay(1)
3030
assertTrue { testReducer.reduceCount == 1 }
3131
}
3232

@@ -41,7 +41,7 @@ class StoreReducerTests : StoreCoroutineTest() {
4141
)
4242

4343
actionList.forEach { testStore.send(it)}
44-
testCoroutineScope.runCurrent()
44+
delay(100)
4545

4646
//add the effect action
4747
actionList.add(TestAction.DoNothingFromEffectAction)

0 commit comments

Comments
 (0)