File tree 1 file changed +30
-5
lines changed
kotlinx-coroutines-core/jvm/test
1 file changed +30
-5
lines changed Original file line number Diff line number Diff line change @@ -6,16 +6,41 @@ package kotlinx.coroutines
6
6
7
7
import kotlin.test.*
8
8
9
+
9
10
class AsyncJvmTest : TestBase () {
10
11
// This must be a common test but it fails on JS because of KT-21961
11
12
@Test
12
13
fun testAsyncWithFinally () = runTest {
13
- launch(Dispatchers .Default ) {
14
-
15
- }
16
-
17
- launch(Dispatchers .IO ) {
14
+ expect(1 )
18
15
16
+ @Suppress(" UNREACHABLE_CODE" )
17
+ val d = async {
18
+ expect(3 )
19
+ try {
20
+ yield () // to main, will cancel
21
+ } finally {
22
+ expect(6 ) // will go there on await
23
+ return @async " Fail" // result will not override cancellation
24
+ }
25
+ expectUnreached()
26
+ " Fail2"
27
+ }
28
+ expect(2 )
29
+ yield () // to async
30
+ expect(4 )
31
+ check(d.isActive && ! d.isCompleted && ! d.isCancelled)
32
+ d.cancel()
33
+ check(! d.isActive && ! d.isCompleted && d.isCancelled)
34
+ check(! d.isActive && ! d.isCompleted && d.isCancelled)
35
+ expect(5 )
36
+ try {
37
+ d.await() // awaits
38
+ expectUnreached() // does not complete normally
39
+ } catch (e: Throwable ) {
40
+ expect(7 )
41
+ check(e is CancellationException )
19
42
}
43
+ check(! d.isActive && d.isCompleted && d.isCancelled)
44
+ finish(8 )
20
45
}
21
46
}
You can’t perform that action at this time.
0 commit comments