Roman Elizarov | 1f74a2d | 2018-06-29 19:19:45 +0300 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. |
| 3 | */ |
| 4 | |
Sergey Mashkov | 199a04c | 2017-11-10 10:43:44 +0300 | [diff] [blame] | 5 | package kotlinx.coroutines.experimental.io |
| 6 | |
| 7 | import com.devexperts.dxlab.lincheck.* |
| 8 | import com.devexperts.dxlab.lincheck.annotations.* |
| 9 | import com.devexperts.dxlab.lincheck.stress.* |
| 10 | import kotlinx.coroutines.experimental.* |
| 11 | import org.junit.* |
| 12 | |
Sergey Mashkov | 199a04c | 2017-11-10 10:43:44 +0300 | [diff] [blame] | 13 | @OpGroupConfigs( |
| 14 | OpGroupConfig(name = "write", nonParallel = true), |
| 15 | OpGroupConfig(name = "read1", nonParallel = true), |
| 16 | OpGroupConfig(name = "read2", nonParallel = true) |
| 17 | ) |
Roman Elizarov | 6129c94 | 2018-01-10 17:34:40 +0300 | [diff] [blame] | 18 | class ByteChannelJoinNoAutoFlushLinearizabilityTest : TestBase() { |
Sergey Mashkov | 199a04c | 2017-11-10 10:43:44 +0300 | [diff] [blame] | 19 | 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 Mashkov | 199a04c | 2017-11-10 10:43:44 +0300 | [diff] [blame] | 38 | 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 Elizarov | 6129c94 | 2018-01-10 17:34:40 +0300 | [diff] [blame] | 48 | 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 Mashkov | 199a04c | 2017-11-10 10:43:44 +0300 | [diff] [blame] | 56 | } |
| 57 | } |