Skip to content

Commit 09223c6

Browse files
authored
Fix tests where coroutine outlive the test body (#4342)
1 parent a932caa commit 09223c6

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

kotlinx-coroutines-core/common/test/ParentCancellationTest.kt

+1
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ class ParentCancellationTest : TestBase() {
158158
}
159159
if (expectParentActive) {
160160
assertTrue(parent.isActive)
161+
parent.cancelAndJoin()
161162
} else {
162163
parent.join()
163164
assertFalse(parent.isActive)

kotlinx-coroutines-core/jvm/test/scheduling/BlockingCoroutineDispatcherTerminationStressTest.kt

+6-2
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,18 @@ class BlockingCoroutineDispatcherTerminationStressTest : TestBase() {
1919
baseDispatcher.close()
2020
}
2121

22+
/**
23+
* Tests that when threads are created to accommodate the new tasks, but then don't receive any tasks for the
24+
* duration of their terminate-on-idling timeout, liveness does not suffer.
25+
*/
2226
@Test
23-
fun testTermination() {
27+
fun testTermination() = runTest {
2428
val rnd = Random()
2529
val deadline = System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(TEST_SECONDS)
2630
while (System.currentTimeMillis() < deadline) {
2731
Thread.sleep(rnd.nextInt(30).toLong())
2832
repeat(rnd.nextInt(5) + 1) {
29-
GlobalScope.launch(ioDispatcher) {
33+
launch(ioDispatcher) {
3034
Thread.sleep(rnd.nextInt(5).toLong())
3135
}
3236
}

0 commit comments

Comments
 (0)