1 /* 2 * Copyright 2016-2021 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 kotlin.test.* 9 10 @Suppress("DEPRECATION") 11 class TestRunBlockingOrderTest: OrderedExecutionTestBase() { 12 13 @Test <lambda>null14 fun testLaunchImmediate() = runBlockingTest { 15 expect(1) 16 launch { 17 expect(2) 18 } 19 finish(3) 20 } 21 22 @Test <lambda>null23 fun testYield() = runBlockingTest { 24 expect(1) 25 launch { 26 expect(2) 27 yield() 28 finish(4) 29 } 30 expect(3) 31 } 32 33 @Test <lambda>null34 fun testLaunchWithDelayCompletes() = runBlockingTest { 35 expect(1) 36 launch { 37 delay(100) 38 finish(3) 39 } 40 expect(2) 41 } 42 43 @Test <lambda>null44 fun testLaunchDelayOrdered() = runBlockingTest { 45 expect(1) 46 launch { 47 delay(200) // long delay 48 finish(4) 49 } 50 launch { 51 delay(100) // shorter delay 52 expect(3) 53 } 54 expect(2) 55 } 56 57 @Test testVeryLongDelaynull58 fun testVeryLongDelay() = runBlockingTest { 59 expect(1) 60 delay(100) // move time forward a bit some that naive time + delay gives an overflow 61 launch { 62 delay(Long.MAX_VALUE / 2) // very long delay 63 finish(4) 64 } 65 launch { 66 delay(100) // short delay 67 expect(3) 68 } 69 expect(2) 70 } 71 72 @Test <lambda>null73 fun testAdvanceUntilIdle_inRunBlocking() = runBlockingTest { 74 expect(1) 75 assertRunsFast { 76 advanceUntilIdle() // ensure this doesn't block forever 77 } 78 finish(2) 79 } 80 }