Skip to content

Commit

Permalink
Add lost tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dkhalanskyjb committed Oct 28, 2021
1 parent 5bbf226 commit a8e43d6
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions kotlinx-coroutines-test/common/test/RunTestTest.kt
Expand Up @@ -217,4 +217,38 @@ class RunTestTest {
}
})

/** Tests that [runTest] completes its job. */
@Test
fun testCompletesOwnJob(): TestResult {
var handlerCalled = false
return testResultMap({
it()
assertTrue(handlerCalled)
}, {
runTest {
coroutineContext.job.invokeOnCompletion {
handlerCalled = true
}
}
})
}

/** Tests that [runTest] doesn't complete the job that was passed to it as an argument. */
@Test
fun testDoesNotCompleteGivenJob(): TestResult {
var handlerCalled = false
val job = Job()
job.invokeOnCompletion {
handlerCalled = true
}
return testResultMap({
it()
assertFalse(handlerCalled)
assertEquals(0, job.children.filter { it.isActive }.count())
}, {
runTest(job) {
assertTrue(coroutineContext.job in job.children)
}
})
}
}

0 comments on commit a8e43d6

Please sign in to comment.