Skip to content

Commit a8e43d6

Browse files
committed
Add lost tests
1 parent 5bbf226 commit a8e43d6

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

kotlinx-coroutines-test/common/test/RunTestTest.kt

+34
Original file line numberDiff line numberDiff line change
@@ -217,4 +217,38 @@ class RunTestTest {
217217
}
218218
})
219219

220+
/** Tests that [runTest] completes its job. */
221+
@Test
222+
fun testCompletesOwnJob(): TestResult {
223+
var handlerCalled = false
224+
return testResultMap({
225+
it()
226+
assertTrue(handlerCalled)
227+
}, {
228+
runTest {
229+
coroutineContext.job.invokeOnCompletion {
230+
handlerCalled = true
231+
}
232+
}
233+
})
234+
}
235+
236+
/** Tests that [runTest] doesn't complete the job that was passed to it as an argument. */
237+
@Test
238+
fun testDoesNotCompleteGivenJob(): TestResult {
239+
var handlerCalled = false
240+
val job = Job()
241+
job.invokeOnCompletion {
242+
handlerCalled = true
243+
}
244+
return testResultMap({
245+
it()
246+
assertFalse(handlerCalled)
247+
assertEquals(0, job.children.filter { it.isActive }.count())
248+
}, {
249+
runTest(job) {
250+
assertTrue(coroutineContext.job in job.children)
251+
}
252+
})
253+
}
220254
}

0 commit comments

Comments
 (0)