blob: e60a0305ac9d906251a67bbd4bdc4245538089e1 [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
Sergey Mashkov199a04c2017-11-10 10:43:44 +03005package kotlinx.coroutines.experimental.io
6
7import com.devexperts.dxlab.lincheck.*
8import com.devexperts.dxlab.lincheck.annotations.*
9import com.devexperts.dxlab.lincheck.stress.*
10import kotlinx.coroutines.experimental.*
11import org.junit.*
12
Sergey Mashkov199a04c2017-11-10 10:43:44 +030013@OpGroupConfigs(
14 OpGroupConfig(name = "write", nonParallel = true),
15 OpGroupConfig(name = "read1", nonParallel = true),
16 OpGroupConfig(name = "read2", nonParallel = true)
17)
Roman Elizarov6129c942018-01-10 17:34:40 +030018class ByteChannelJoinNoAutoFlushLinearizabilityTest : TestBase() {
Sergey Mashkov199a04c2017-11-10 10:43:44 +030019 private lateinit var from: ByteChannel
20 private lateinit var to: ByteChannel
21
22 private val lr = LinTesting()
23
24 @Reset
25 fun reset() {
26 from = ByteChannel(false)
27 to = ByteChannel(false)
28 }
29
30 @Operation(runOnce = true, group = "read1")
31 fun read() = lr.run("read") {
32 to.readLong()
33 }
34
35 @Operation(runOnce = true, group = "write")
36 fun write() = lr.run("write") {
37 from.writeLong(0x1122334455667788L)
Sergey Mashkov199a04c2017-11-10 10:43:44 +030038 from.flush()
39 }
40
41 @Operation(runOnce = true, group = "read2")
42 fun joinTo() = lr.run("join") {
43 from.joinTo(to, true)
44 }
45
46 @Test
47 fun test() {
Roman Elizarov6129c942018-01-10 17:34:40 +030048 val options = StressOptions()
49 .iterations(100)
50 .invocationsPerIteration(1000 * stressTestMultiplier)
51 .addThread(1, 2)
52 .addThread(1, 1)
53 .addThread(1, 1)
54 .verifier(LinVerifier::class.java)
55 LinChecker.check(ByteChannelJoinNoAutoFlushLinearizabilityTest::class.java, options)
Sergey Mashkov199a04c2017-11-10 10:43:44 +030056 }
57}