Skip to content

Commit ca1093c

Browse files
committed
Restore AsyncJvmTest
1 parent d4fabbf commit ca1093c

File tree

1 file changed

+30
-5
lines changed

1 file changed

+30
-5
lines changed

kotlinx-coroutines-core/jvm/test/AsyncJvmTest.kt

+30-5
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,41 @@ package kotlinx.coroutines
66

77
import kotlin.test.*
88

9+
910
class 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
}

0 commit comments

Comments
 (0)