Skip to content

Commit 1da7311

Browse files
committed
Restore AsyncJvmTest
1 parent 1652bb9 commit 1da7311

File tree

1 file changed

+30
-20
lines changed

1 file changed

+30
-20
lines changed

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

+30-20
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,42 @@
44

55
package kotlinx.coroutines
66

7-
import kotlin.coroutines.*
87
import kotlin.test.*
98

109
class AsyncJvmTest : TestBase() {
1110
// This must be a common test but it fails on JS because of KT-21961
12-
suspend fun test() {
13-
println("test.begin")
14-
delay(5000)
15-
println("test.end")
16-
}
17-
18-
suspend fun proxy() {
19-
println("?")
20-
test()
21-
println("?")
22-
}
11+
@Test
12+
fun testAsyncWithFinally() = runTest {
13+
expect(1)
2314

24-
// @Test
25-
fun main() {
26-
println("AA")
27-
runBlocking {
28-
withTimeout(100) {
29-
proxy()
30-
println()
15+
@Suppress("UNREACHABLE_CODE")
16+
val d = async {
17+
expect(3)
18+
try {
19+
yield() // to main, will cancel
20+
} finally {
21+
expect(6) // will go there on await
22+
return@async "Fail" // result will not override cancellation
3123
}
32-
println()
24+
expectUnreached()
25+
"Fail2"
26+
}
27+
expect(2)
28+
yield() // to async
29+
expect(4)
30+
check(d.isActive && !d.isCompleted && !d.isCancelled)
31+
d.cancel()
32+
check(!d.isActive && !d.isCompleted && d.isCancelled)
33+
check(!d.isActive && !d.isCompleted && d.isCancelled)
34+
expect(5)
35+
try {
36+
d.await() // awaits
37+
expectUnreached() // does not complete normally
38+
} catch (e: Throwable) {
39+
expect(7)
40+
check(e is CancellationException)
3341
}
42+
check(!d.isActive && d.isCompleted && d.isCancelled)
43+
finish(8)
3444
}
3545
}

0 commit comments

Comments
 (0)