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