File tree Expand file tree Collapse file tree 1 file changed +30
-5
lines changed
kotlinx-coroutines-core/jvm/test Expand file tree Collapse file tree 1 file changed +30
-5
lines changed Original file line number Diff line number Diff line change @@ -6,16 +6,41 @@ package kotlinx.coroutines
66
77import kotlin.test.*
88
9+
910class AsyncJvmTest : TestBase () {
1011 // This must be a common test but it fails on JS because of KT-21961
1112 @Test
1213 fun testAsyncWithFinally () = runTest {
13- launch(Dispatchers .Default ) {
14-
15- }
16-
17- launch(Dispatchers .IO ) {
14+ expect(1 )
1815
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 )
1942 }
43+ check(! d.isActive && d.isCompleted && d.isCancelled)
44+ finish(8 )
2045 }
2146}
You can’t perform that action at this time.
0 commit comments