• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2016-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3  */
4 
5 package kotlinx.coroutines.test
6 
7 import kotlinx.coroutines.*
8 import org.junit.*
9 import kotlin.coroutines.*
10 
11 class TestRunBlockingOrderTest : TestBase() {
12     @Test
<lambda>null13     fun testLaunchImmediate() = runBlockingTest {
14         expect(1)
15         launch {
16             expect(2)
17         }
18         finish(3)
19     }
20 
21     @Test
<lambda>null22     fun testYield() = runBlockingTest {
23         expect(1)
24         launch {
25             expect(2)
26             yield()
27             finish(4)
28         }
29         expect(3)
30     }
31 
32     @Test
<lambda>null33     fun testLaunchWithDelayCompletes() = runBlockingTest {
34         expect(1)
35         launch {
36             delay(100)
37             finish(3)
38         }
39         expect(2)
40     }
41 
42     @Test
<lambda>null43     fun testLaunchDelayOrdered() = runBlockingTest {
44         expect(1)
45         launch {
46             delay(200) // long delay
47             finish(4)
48         }
49         launch  {
50             delay(100) // shorter delay
51             expect(3)
52         }
53         expect(2)
54     }
55 
56     @Test
<lambda>null57     fun testInfiniteDelay() = runBlockingTest {
58         expect(1)
59         delay(100) // move time forward a bit some that naive time + delay gives an overflow
60         launch {
61             delay(Long.MAX_VALUE) // infinite delay
62             finish(4)
63         }
64         launch  {
65             delay(100) // short delay
66             expect(3)
67         }
68         expect(2)
69     }
70 
71     @Test
<lambda>null72     fun testAdvanceUntilIdle_inRunBlocking() = runBlockingTest {
73         expect(1)
74         assertRunsFast {
75             advanceUntilIdle()   // ensure this doesn't block forever
76         }
77         finish(2)
78     }
79 }
80