-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathTestRunBlockingOrderTest.kt
58 lines (52 loc) · 1.21 KB
/
TestRunBlockingOrderTest.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
* Copyright 2016-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/
package kotlinx.coroutines.test
import kotlinx.coroutines.*
import org.junit.*
class TestRunBlockingOrderTest : TestBase() {
@Test
fun testLaunchImmediate() = runBlockingTest {
expect(1)
launch {
expect(2)
}
finish(3)
}
@Test
fun testLaunchWithDelayCompletes() = runBlockingTest {
expect(1)
launch {
delay(100)
finish(3)
}
expect(2)
}
@Test
fun testLaunchDelayOrdered() = runBlockingTest {
expect(1)
launch {
delay(200) // long delay
finish(4)
}
launch {
delay(100) // shorter delay
expect(3)
}
expect(2)
}
@Test
fun testInfiniteDelay() = runBlockingTest {
expect(1)
delay(100) // move time forward a bit some that naive time + delay gives an overflow
launch {
delay(Long.MAX_VALUE) // infinite delay
finish(4)
}
launch {
delay(100) // short delay
expect(3)
}
expect(2)
}
}