1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
/*
* Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/
@file:Suppress("NAMED_ARGUMENTS_NOT_ALLOWED") // KT-21913
package kotlinx.coroutines
import kotlin.test.*
// see https://github.com/Kotlin/kotlinx.coroutines/issues/585
class FailedJobTest : TestBase() {
@Test
fun testCancelledJob() = runTest {
expect(1)
val job = launch {
expectUnreached()
}
expect(2)
job.cancelAndJoin()
finish(3)
assertTrue(job.isCompleted)
assertTrue(!job.isActive)
assertTrue(job.isCancelled)
}
@Test
fun testFailedJob() = runTest(
unhandled = listOf({it -> it is TestException })
) {
expect(1)
val job = launch(NonCancellable) {
expect(3)
throw TestException()
}
expect(2)
job.join()
finish(4)
assertTrue(job.isCompleted)
assertTrue(!job.isActive)
assertTrue(job.isCancelled)
}
@Test
fun testFailedChildJob() = runTest(
unhandled = listOf({it -> it is TestException })
) {
expect(1)
val job = launch(NonCancellable) {
expect(3)
launch {
throw TestException()
}
}
expect(2)
job.join()
finish(4)
assertTrue(job.isCompleted)
assertTrue(!job.isActive)
assertTrue(job.isCancelled)
}
}
|