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.* |
| 5 | import org.junit.runner.* |
| 6 | import org.junit.runners.* |
| 7 | |
| 8 | @RunWith(Parameterized::class) |
| 9 | class ArrayChannelStressTest(private val capacity: Int) : TestBase() { |
| 10 | |
| 11 | companion object { |
| 12 | @Parameterized.Parameters(name = "{0}, nSenders={1}, nReceivers={2}") |
| 13 | @JvmStatic |
| 14 | fun params(): Collection<Array<Any>> = listOf(1, 10, 100, 100_000, 1_000_000).map { arrayOf<Any>(it) } |
| 15 | } |
| 16 | |
| 17 | @Test |
| 18 | fun testStress() = runTest { |
| 19 | val n = 100_000 * stressTestMultiplier |
| 20 | val q = ArrayChannel<Int>(capacity) |
| 21 | val sender = launch(kotlin.coroutines.experimental.coroutineContext) { |
| 22 | for (i in 1..n) { |
| 23 | q.send(i) |
| 24 | } |
| 25 | expect(2) |
| 26 | } |
| 27 | val receiver = launch(kotlin.coroutines.experimental.coroutineContext) { |
| 28 | for (i in 1..n) { |
| 29 | val next = q.receive() |
| 30 | check(next == i) |
| 31 | } |
| 32 | expect(3) |
| 33 | } |
| 34 | expect(1) |
| 35 | sender.join() |
| 36 | receiver.join() |
| 37 | finish(4) |
| 38 | } |
| 39 | } |