3
3
*/
4
4
@file:Suppress(" unused" )
5
5
6
- package kotlinx.coroutines.linearizability
6
+ package kotlinx.coroutines.lincheck
7
7
8
8
import kotlinx.coroutines.*
9
9
import kotlinx.coroutines.channels.*
10
10
import kotlinx.coroutines.channels.Channel.Factory.CONFLATED
11
11
import kotlinx.coroutines.channels.Channel.Factory.RENDEZVOUS
12
12
import kotlinx.coroutines.channels.Channel.Factory.UNLIMITED
13
13
import kotlinx.coroutines.selects.*
14
+ import org.jetbrains.kotlinx.lincheck.*
14
15
import org.jetbrains.kotlinx.lincheck.annotations.*
15
16
import org.jetbrains.kotlinx.lincheck.annotations.Operation
16
17
import org.jetbrains.kotlinx.lincheck.paramgen.*
17
18
import org.jetbrains.kotlinx.lincheck.verifier.*
18
- import org.junit.*
19
19
20
- class RendezvousChannelLCStressTest : ChannelLCStressTestBase (
20
+ class RendezvousChannelLincheckTest : ChannelLincheckTestBase (
21
21
c = Channel (RENDEZVOUS ),
22
22
sequentialSpecification = SequentialRendezvousChannel : :class.java
23
23
)
24
24
class SequentialRendezvousChannel : SequentialIntChannelBase (RENDEZVOUS )
25
25
26
- class Array1ChannelLCStressTest : ChannelLCStressTestBase (
26
+ class Array1ChannelLincheckTest : ChannelLincheckTestBase (
27
27
c = Channel (1),
28
28
sequentialSpecification = SequentialArray1RendezvousChannel : :class.java
29
29
)
30
30
class SequentialArray1RendezvousChannel : SequentialIntChannelBase (1 )
31
31
32
- class Array2ChannelLCStressTest : ChannelLCStressTestBase (
32
+ class Array2ChannelLincheckTest : ChannelLincheckTestBase (
33
33
c = Channel (2),
34
34
sequentialSpecification = SequentialArray2RendezvousChannel : :class.java
35
35
)
36
36
class SequentialArray2RendezvousChannel : SequentialIntChannelBase (2 )
37
37
38
- class UnlimitedChannelLCStressTest : ChannelLCStressTestBase (
38
+ class UnlimitedChannelLincheckTest : ChannelLincheckTestBase (
39
39
c = Channel (UNLIMITED ),
40
40
sequentialSpecification = SequentialUnlimitedChannel : :class.java
41
41
)
42
42
class SequentialUnlimitedChannel : SequentialIntChannelBase (UNLIMITED )
43
43
44
- class ConflatedChannelLCStressTest : ChannelLCStressTestBase (
44
+ class ConflatedChannelLincheckTest : ChannelLincheckTestBase (
45
45
c = Channel (CONFLATED ),
46
46
sequentialSpecification = SequentialConflatedChannel : :class.java
47
47
)
@@ -51,8 +51,11 @@ class SequentialConflatedChannel : SequentialIntChannelBase(CONFLATED)
51
51
Param (name = " value" , gen = IntGen ::class , conf = " 1:5" ),
52
52
Param (name = " closeToken" , gen = IntGen ::class , conf = " 1:3" )
53
53
)
54
- abstract class ChannelLCStressTestBase (private val c : Channel <Int >, private val sequentialSpecification : Class <* >) {
55
- @Operation
54
+ abstract class ChannelLincheckTestBase (
55
+ private val c : Channel <Int >,
56
+ private val sequentialSpecification : Class <* >
57
+ ) : AbstractLincheckTest() {
58
+ @Operation(promptCancellation = true )
56
59
suspend fun send (@Param(name = " value" ) value : Int ): Any = try {
57
60
c.send(value)
58
61
} catch (e: NumberedCancellationException ) {
@@ -74,7 +77,7 @@ abstract class ChannelLCStressTestBase(private val c: Channel<Int>, private val
74
77
e.testResult
75
78
}
76
79
77
- @Operation
80
+ @Operation(promptCancellation = true )
78
81
suspend fun receive (): Any = try {
79
82
c.receive()
80
83
} catch (e: NumberedCancellationException ) {
@@ -96,7 +99,7 @@ abstract class ChannelLCStressTestBase(private val c: Channel<Int>, private val
96
99
e.testResult
97
100
}
98
101
99
- @Operation
102
+ @Operation(causesBlocking = true )
100
103
fun close (@Param(name = " closeToken" ) token : Int ): Boolean = c.close(NumberedCancellationException (token))
101
104
102
105
// TODO: this operation should be (and can be!) linearizable, but is not
@@ -113,11 +116,8 @@ abstract class ChannelLCStressTestBase(private val c: Channel<Int>, private val
113
116
// @Operation
114
117
fun isEmpty () = c.isEmpty
115
118
116
- @Test
117
- fun test () = LCStressOptionsDefault ()
118
- .actorsBefore(0 )
119
- .sequentialSpecification(sequentialSpecification)
120
- .check(this ::class )
119
+ override fun <O : Options <O , * >> O.customize (isStressTest : Boolean ): O =
120
+ actorsBefore(0 ).sequentialSpecification(sequentialSpecification)
121
121
}
122
122
123
123
private class NumberedCancellationException (number : Int ) : CancellationException() {
0 commit comments