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