Roman Elizarov | 1f74a2d | 2018-06-29 19:19:45 +0300 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. |
| 3 | */ |
| 4 | |
Vsevolod Tolstopyatov | 03d2ff7 | 2018-05-29 17:28:20 +0300 | [diff] [blame] | 5 | package kotlinx.coroutines.experimental.channels |
| 6 | |
| 7 | import kotlinx.coroutines.experimental.* |
| 8 | import org.junit.* |
| 9 | |
| 10 | class TickerChannelTest : TestBase() { |
Vsevolod Tolstopyatov | 03d2ff7 | 2018-05-29 17:28:20 +0300 | [diff] [blame] | 11 | @Test |
| 12 | fun testFixedDelayChannelBackpressure() = runTest { |
Roman Elizarov | b5328a7 | 2018-06-06 18:31:21 +0300 | [diff] [blame] | 13 | val delayChannel = ticker(delay = 100, initialDelay = 0, mode = TickerMode.FIXED_DELAY) |
Vsevolod Tolstopyatov | 03d2ff7 | 2018-05-29 17:28:20 +0300 | [diff] [blame] | 14 | 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 | } |