Skip to content

Commit f4e7b68

Browse files
committed
Fixed LockFreeTaskQueueLinearizabilityTest
Looks like we have to copy-and-paste two version for single/multi-consumer LockFreeTaskQueue. For details on this problem see devexperts/lin-check#9
1 parent 53d2e25 commit f4e7b68

File tree

1 file changed

+30
-7
lines changed

1 file changed

+30
-7
lines changed

core/kotlinx-coroutines-core/test/internal/LockFreeTaskQueueLinearizabilityTest.kt

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,39 @@ import kotlin.test.*
1414

1515
@OpGroupConfigs(OpGroupConfig(name = "consumer", nonParallel = true))
1616
@Param(name = "value", gen = IntGen::class, conf = "1:3")
17-
class LockFreeTaskQueueLinearizabilityTestSC : LockFreeTaskQueueLinearizabilityTestBase(singleConsumer = true)
17+
class LockFreeTaskQueueLinearizabilityTestSC : LockFreeTaskQueueLinearizabilityTestBase() {
18+
private lateinit var q: LockFreeTaskQueue<Int>
19+
20+
@Reset
21+
fun resetQueue() {
22+
q = LockFreeTaskQueue(singleConsumer = true) // SINGLE-CONSUMER !!!
23+
}
24+
25+
@Operation
26+
fun close() = q.close()
27+
28+
@Operation
29+
fun addLast(@Param(name = "value") value: Int) = q.addLast(value)
30+
31+
/**
32+
* Note, that removeFirstOrNull is not linearizable w.r.t. to addLast, so here
33+
* we test only linearizability of close.
34+
*/
35+
// @Operation(group = "consumer")
36+
// fun removeFirstOrNull() = q.removeFirstOrNull()
37+
38+
@Test
39+
fun testSC() = linTest()
40+
}
1841

1942
@OpGroupConfigs(OpGroupConfig(name = "consumer", nonParallel = true))
2043
@Param(name = "value", gen = IntGen::class, conf = "1:3")
21-
class LockFreeTaskQueueLinearizabilityTestMC : LockFreeTaskQueueLinearizabilityTestBase(singleConsumer = false)
22-
23-
open class LockFreeTaskQueueLinearizabilityTestBase(
24-
private val singleConsumer: Boolean
25-
) : TestBase() {
44+
class LockFreeTaskQueueLinearizabilityTestMC : LockFreeTaskQueueLinearizabilityTestBase() {
2645
private lateinit var q: LockFreeTaskQueue<Int>
2746

2847
@Reset
2948
fun resetQueue() {
30-
q = LockFreeTaskQueue(singleConsumer)
49+
q = LockFreeTaskQueue(singleConsumer = false) // MULTI-CONSUMER !!!
3150
}
3251

3352
@Operation
@@ -44,6 +63,10 @@ open class LockFreeTaskQueueLinearizabilityTestBase(
4463
// fun removeFirstOrNull() = q.removeFirstOrNull()
4564

4665
@Test
66+
fun testMC() = linTest()
67+
}
68+
69+
open class LockFreeTaskQueueLinearizabilityTestBase : TestBase() {
4770
fun linTest() {
4871
val options = StressOptions()
4972
.iterations(100 * stressTestMultiplierSqrt)

0 commit comments

Comments
 (0)