blob: 43c947602aff7ec5ef748309a3b01a46a4c4352f [file] [log] [blame]
Roman Elizarova7db8ec2017-12-21 22:45:12 +03001/*
Roman Elizarov1f74a2d2018-06-29 19:19:45 +03002 * Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
Roman Elizarova7db8ec2017-12-21 22:45:12 +03003 */
4
Roman Elizarovc43a9be2017-11-09 15:38:45 +03005package kotlinx.coroutines.experimental.channels
6
7import com.devexperts.dxlab.lincheck.LinChecker
8import com.devexperts.dxlab.lincheck.annotations.Operation
9import com.devexperts.dxlab.lincheck.annotations.Param
10import com.devexperts.dxlab.lincheck.annotations.Reset
11import com.devexperts.dxlab.lincheck.paramgen.IntGen
Roman Elizarov6129c942018-01-10 17:34:40 +030012import com.devexperts.dxlab.lincheck.stress.*
13import kotlinx.coroutines.experimental.*
Roman Elizarovc43a9be2017-11-09 15:38:45 +030014import org.junit.Test
15
Roman Elizarovc43a9be2017-11-09 15:38:45 +030016@Param(name = "value", gen = IntGen::class, conf = "1:3")
Roman Elizarov6129c942018-01-10 17:34:40 +030017class ChannelLinearizabilityTest : TestBase() {
Roman Elizarovc43a9be2017-11-09 15:38:45 +030018 private val lt = LinTesting()
19 private lateinit var channel: Channel<Int>
20
21 @Reset
22 fun reset() {
23 channel = Channel<Int>()
24 }
25
26 @Operation(runOnce = true)
27 fun send1(@Param(name = "value") value: Int) = lt.run("send1") { channel.send(value) }
28
29 @Operation(runOnce = true)
30 fun send2(@Param(name = "value") value: Int) = lt.run("send2") { channel.send(value) }
31
32 @Operation(runOnce = true)
33 fun send3(@Param(name = "value") value: Int) = lt.run("send3") { channel.send(value) }
34
35 @Operation(runOnce = true)
36 fun receive1() = lt.run("receive1") { channel.receive() }
37
38 @Operation(runOnce = true)
39 fun receive2() = lt.run("receive2") { channel.receive() }
40
41 @Operation(runOnce = true)
42 fun receive3() = lt.run("receive3") { channel.receive() }
43
44// @Operation(runOnce = true)
45// fun close1() = lt.run("close1") { channel.close(IOException("close1")) }
46//
47// @Operation(runOnce = true)
48// fun close2() = lt.run("close2") { channel.close(IOException("close2")) }
49
50 @Test
51 fun testLinearizability() {
Roman Elizarov6129c942018-01-10 17:34:40 +030052 val options = StressOptions()
53 .iterations(100)
54 .invocationsPerIteration(1000 * stressTestMultiplier)
55 .addThread(1, 3)
56 .addThread(1, 3)
57 .addThread(1, 3)
58 .verifier(LinVerifier::class.java)
59 LinChecker.check(ChannelLinearizabilityTest::class.java, options)
Roman Elizarovc43a9be2017-11-09 15:38:45 +030060 }
61}