1 package kotlinx.coroutines.test 2 3 import kotlinx.coroutines.* 4 import org.junit.* 5 import kotlin.coroutines.* 6 import kotlin.test.assertEquals 7 8 class TestCoroutineDispatcherOrderTest : TestBase() { 9 10 @Test testAdvanceTimeBy_progressesOnEachDelaynull11 fun testAdvanceTimeBy_progressesOnEachDelay() { 12 val dispatcher = TestCoroutineDispatcher() 13 val scope = TestCoroutineScope(dispatcher) 14 15 expect(1) 16 scope.launch { 17 expect(2) 18 delay(1_000) 19 assertEquals(1_000, dispatcher.currentTime) 20 expect(4) 21 delay(5_00) 22 assertEquals(1_500, dispatcher.currentTime) 23 expect(5) 24 delay(501) 25 assertEquals(2_001, dispatcher.currentTime) 26 expect(7) 27 } 28 expect(3) 29 assertEquals(0, dispatcher.currentTime) 30 dispatcher.advanceTimeBy(2_000) 31 expect(6) 32 assertEquals(2_000, dispatcher.currentTime) 33 dispatcher.advanceTimeBy(2) 34 expect(8) 35 assertEquals(2_002, dispatcher.currentTime) 36 scope.cleanupTestCoroutines() 37 finish(9) 38 } 39 }