blob: c9b3f46061978e06700c0421fc4bad1b84539cb6 [file] [log] [blame]
Roman Elizarov1f74a2d2018-06-29 19:19:45 +03001/*
2 * Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3 */
4
Vsevolod Tolstopyatov03d2ff72018-05-29 17:28:20 +03005package kotlinx.coroutines.experimental.channels
6
7import kotlinx.coroutines.experimental.*
8import org.junit.*
9
10class TickerChannelTest : TestBase() {
Vsevolod Tolstopyatov03d2ff72018-05-29 17:28:20 +030011 @Test
12 fun testFixedDelayChannelBackpressure() = runTest {
Roman Elizarovb5328a72018-06-06 18:31:21 +030013 val delayChannel = ticker(delay = 100, initialDelay = 0, mode = TickerMode.FIXED_DELAY)
Vsevolod Tolstopyatov03d2ff72018-05-29 17:28:20 +030014 delayChannel.checkNotEmpty()
15 delayChannel.checkEmpty()
16
17 delay(150)
18 delayChannel.checkNotEmpty()
19 delay(50)
20 delayChannel.checkEmpty()
21 delay(52)
22 delayChannel.checkNotEmpty()
23 delayChannel.cancel()
24 }
25
26 @Test
27 fun testDelayChannelBackpressure() = runTest {
28 val delayChannel = ticker(delay = 100, initialDelay = 0)
29 delayChannel.checkNotEmpty()
30 delayChannel.checkEmpty()
31
32 delay(150)
33 delayChannel.checkNotEmpty()
34 delay(52)
35 delayChannel.checkNotEmpty()
36 delay(50)
37 delayChannel.checkEmpty()
38 delay(52)
39 delayChannel.checkNotEmpty()
40 delayChannel.cancel()
41 }
42
43 @Test
44 fun testDelayChannelBackpressure2() = runTest {
45 val delayChannel = ticker(delay = 100, initialDelay = 0)
46 delayChannel.checkNotEmpty()
47 delayChannel.checkEmpty()
48
49 delay(250)
50 delayChannel.checkNotEmpty()
51 delay(51)
52 delayChannel.checkNotEmpty()
53 delay(51)
54 delayChannel.checkEmpty()
55 delay(51)
56 delayChannel.checkNotEmpty()
57 delayChannel.cancel()
58 }
59}