1 package kotlinx.coroutines.test 2 3 import kotlinx.coroutines.testing.* 4 import kotlinx.coroutines.* 5 import kotlin.test.* 6 7 @Suppress("DEPRECATION", "DEPRECATION_ERROR") 8 class TestRunBlockingOrderTest: OrderedExecutionTestBase() { 9 10 @Test <lambda>null11 fun testLaunchImmediate() = runBlockingTest { 12 expect(1) 13 launch { 14 expect(2) 15 } 16 finish(3) 17 } 18 19 @Test <lambda>null20 fun testYield() = runBlockingTest { 21 expect(1) 22 launch { 23 expect(2) 24 yield() 25 finish(4) 26 } 27 expect(3) 28 } 29 30 @Test <lambda>null31 fun testLaunchWithDelayCompletes() = runBlockingTest { 32 expect(1) 33 launch { 34 delay(100) 35 finish(3) 36 } 37 expect(2) 38 } 39 40 @Test <lambda>null41 fun testLaunchDelayOrdered() = runBlockingTest { 42 expect(1) 43 launch { 44 delay(200) // long delay 45 finish(4) 46 } 47 launch { 48 delay(100) // shorter delay 49 expect(3) 50 } 51 expect(2) 52 } 53 54 @Test testVeryLongDelaynull55 fun testVeryLongDelay() = runBlockingTest { 56 expect(1) 57 delay(100) // move time forward a bit some that naive time + delay gives an overflow 58 launch { 59 delay(Long.MAX_VALUE / 2) // very long delay 60 finish(4) 61 } 62 launch { 63 delay(100) // short delay 64 expect(3) 65 } 66 expect(2) 67 } 68 69 @Test <lambda>null70 fun testAdvanceUntilIdle_inRunBlocking() = runBlockingTest { 71 expect(1) 72 assertRunsFast { 73 advanceUntilIdle() // ensure this doesn't block forever 74 } 75 finish(2) 76 } 77 } 78