• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download

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