File tree 1 file changed +30
-20
lines changed
kotlinx-coroutines-core/jvm/test
1 file changed +30
-20
lines changed Original file line number Diff line number Diff line change 4
4
5
5
package kotlinx.coroutines
6
6
7
- import kotlin.coroutines.*
8
7
import kotlin.test.*
9
8
10
9
class AsyncJvmTest : TestBase () {
11
10
// 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 )
23
14
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
31
23
}
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 )
33
41
}
42
+ check(! d.isActive && d.isCompleted && d.isCancelled)
43
+ finish(8 )
34
44
}
35
45
}
You can’t perform that action at this time.
0 commit comments