Vsevolod Tolstopyatov | 9619134 | 2018-04-20 18:13:33 +0300 | [diff] [blame] | 1 | package kotlinx.coroutines.experimental.channels |
| 2 | |
| 3 | import kotlinx.coroutines.experimental.* |
| 4 | import org.junit.runner.* |
| 5 | import org.junit.runners.* |
| 6 | import kotlin.coroutines.experimental.* |
| 7 | import kotlin.test.* |
| 8 | |
| 9 | @RunWith(Parameterized::class) |
| 10 | class SendReceiveJvmStressTest(private val channel: Channel<Int>) : TestBase() { |
| 11 | |
| 12 | companion object { |
| 13 | @Parameterized.Parameters(name = "{0}") |
| 14 | @JvmStatic |
| 15 | fun params(): Collection<Array<Any>> = listOf( |
| 16 | ArrayChannel<Int>(1), |
| 17 | ArrayChannel<Int>(10), |
| 18 | ArrayChannel<Int>(1_000_000), |
| 19 | LinkedListChannel<Int>(), |
| 20 | RendezvousChannel<Int>() |
| 21 | ).map { arrayOf<Any>(it) } |
| 22 | } |
| 23 | |
| 24 | @Test |
| 25 | fun testStress() = runTest { |
| 26 | val n = 100_000 * stressTestMultiplier |
| 27 | val sender = launch(coroutineContext) { |
| 28 | for (i in 1..n) { |
| 29 | channel.send(i) |
| 30 | } |
| 31 | expect(2) |
| 32 | } |
| 33 | val receiver = launch(coroutineContext) { |
| 34 | for (i in 1..n) { |
| 35 | val next = channel.receive() |
| 36 | check(next == i) |
| 37 | } |
| 38 | expect(3) |
| 39 | } |
| 40 | expect(1) |
| 41 | sender.join() |
| 42 | receiver.join() |
| 43 | finish(4) |
| 44 | } |
| 45 | } |