Skip to content

Commit 4f24a7a

Browse files
ndkovalelizarov
authored andcommitted
Update lincheck to 2.5.3 and re-write the corresponding tests
1 parent 1f77783 commit 4f24a7a

15 files changed

+342
-515
lines changed

build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ allprojects {
101101
kotlin_version = rootProject.properties['kotlin_snapshot_version']
102102
}
103103

104-
if (build_snapshot_train || atomicfu_version.endsWith("-SNAPSHOT")) {
104+
if (build_snapshot_train || atomicfu_version.endsWith("-SNAPSHOT") || lincheck_version.endsWith("-SNAPSHOT")) {
105105
repositories {
106106
mavenLocal()
107107
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }

gradle.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ kotlin_version=1.3.61
1111
junit_version=4.12
1212
atomicfu_version=0.14.1
1313
html_version=0.6.8
14-
lincheck_version=2.0
14+
lincheck_version=2.5.3
1515
dokka_version=0.9.16-rdev-2-mpp-hacks
1616
byte_buddy_version=1.9.3
1717
reactor_vesion=3.2.5.RELEASE

kotlinx-coroutines-core/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ configurations {
4848

4949
kotlin.sourceSets {
5050
jvmTest.dependencies {
51-
api "com.devexperts.lincheck:lincheck:$lincheck_version"
51+
api "org.jetbrains.kotlinx:lincheck:$lincheck_version"
5252
api "com.esotericsoftware:kryo:4.0.0"
5353
implementation project (":android-unit-tests")
5454
}

kotlinx-coroutines-core/common/test/channels/TestChannelKind.kt

+18-37
Original file line numberDiff line numberDiff line change
@@ -7,45 +7,26 @@ package kotlinx.coroutines.channels
77
import kotlinx.coroutines.*
88
import kotlinx.coroutines.selects.*
99

10-
enum class TestChannelKind {
11-
RENDEZVOUS {
12-
override fun create(): Channel<Int> = Channel(Channel.RENDEZVOUS)
13-
override fun toString(): String = "RendezvousChannel"
14-
},
15-
ARRAY_1 {
16-
override fun create(): Channel<Int> = Channel(1)
17-
override fun toString(): String = "ArrayChannel(1)"
18-
},
19-
ARRAY_10 {
20-
override fun create(): Channel<Int> = Channel(10)
21-
override fun toString(): String = "ArrayChannel(10)"
22-
},
23-
LINKED_LIST {
24-
override fun create(): Channel<Int> = Channel(Channel.UNLIMITED)
25-
override fun toString(): String = "LinkedListChannel"
26-
},
27-
CONFLATED {
28-
override fun create(): Channel<Int> = Channel(Channel.CONFLATED)
29-
override fun toString(): String = "ConflatedChannel"
30-
override val isConflated: Boolean get() = true
31-
},
32-
ARRAY_BROADCAST_1 {
33-
override fun create(): Channel<Int> = ChannelViaBroadcast(BroadcastChannel(1))
34-
override fun toString(): String = "ArrayBroadcastChannel(1)"
35-
},
36-
ARRAY_BROADCAST_10 {
37-
override fun create(): Channel<Int> = ChannelViaBroadcast(BroadcastChannel(10))
38-
override fun toString(): String = "ArrayBroadcastChannel(10)"
39-
},
40-
CONFLATED_BROADCAST {
41-
override fun create(): Channel<Int> = ChannelViaBroadcast(ConflatedBroadcastChannel<Int>())
42-
override fun toString(): String = "ConflatedBroadcastChannel"
43-
override val isConflated: Boolean get() = true
44-
}
10+
enum class TestChannelKind(val capacity: Int,
11+
private val description: String,
12+
private val viaBroadcast: Boolean = false
13+
) {
14+
RENDEZVOUS(0, "RendezvousChannel"),
15+
ARRAY_1(1, "ArrayChannel(1)"),
16+
ARRAY_2(2, "ArrayChannel(2)"),
17+
ARRAY_10(10, "ArrayChannel(10)"),
18+
LINKED_LIST(Channel.UNLIMITED, "LinkedListChannel"),
19+
CONFLATED(Channel.CONFLATED, "ConflatedChannel"),
20+
ARRAY_1_BROADCAST(1, "ArrayBroadcastChannel(1)", viaBroadcast = true),
21+
ARRAY_10_BROADCAST(10, "ArrayBroadcastChannel(10)", viaBroadcast = true),
22+
CONFLATED_BROADCAST(Channel.CONFLATED, "ConflatedBroadcastChannel", viaBroadcast = true)
4523
;
4624

47-
abstract fun create(): Channel<Int>
48-
open val isConflated: Boolean get() = false
25+
fun create(): Channel<Int> = if (viaBroadcast) ChannelViaBroadcast(BroadcastChannel(capacity))
26+
else Channel(capacity)
27+
28+
val isConflated get() = capacity == Channel.CONFLATED
29+
override fun toString(): String = description
4930
}
5031

5132
private class ChannelViaBroadcast<E>(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright 2016-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
package kotlinx.coroutines
5+
6+
import org.jetbrains.kotlinx.lincheck.*
7+
import org.jetbrains.kotlinx.lincheck.strategy.stress.*
8+
import kotlin.reflect.*
9+
10+
class LCStressOptionsDefault : StressOptions() {
11+
init {
12+
iterations(100 * stressTestMultiplierCbrt)
13+
invocationsPerIteration(1000 * stressTestMultiplierCbrt)
14+
actorsBefore(if (isStressTest) 3 else 0)
15+
threads(3)
16+
actorsPerThread(if (isStressTest) 3 else 2)
17+
}
18+
}
19+
20+
fun Options<*,*>.check(testClass: KClass<*>) = LinChecker.check(testClass.java, this)

kotlinx-coroutines-core/jvm/test/TestBase.kt

+4
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ package kotlinx.coroutines
77
import kotlinx.coroutines.internal.*
88
import kotlinx.coroutines.scheduling.*
99
import org.junit.*
10+
import java.lang.Math.*
1011
import java.util.*
1112
import java.util.concurrent.atomic.*
1213
import kotlin.coroutines.*
14+
import kotlin.math.*
1315
import kotlin.test.*
1416

1517
private val VERBOSE = systemProp("test.verbose", false)
@@ -26,6 +28,8 @@ public val stressTestMultiplierSqrt = if (isStressTest) 5 else 1
2628
*/
2729
public actual val stressTestMultiplier = stressTestMultiplierSqrt * stressTestMultiplierSqrt
2830

31+
public val stressTestMultiplierCbrt = cbrt(stressTestMultiplier.toDouble()).roundToInt()
32+
2933
/**
3034
* Base class for tests, so that tests for predictable scheduling of actions in multiple coroutines sharing a single
3135
* thread can be written. Use it like this:

kotlinx-coroutines-core/jvm/test/internal/SegmentQueueLCStressTest.kt

-30
This file was deleted.

kotlinx-coroutines-core/jvm/test/linearizability/ChannelCloseLCStressTest.kt

-82
This file was deleted.

kotlinx-coroutines-core/jvm/test/linearizability/ChannelIsClosedLCStressTest.kt

-54
This file was deleted.

kotlinx-coroutines-core/jvm/test/linearizability/ChannelLCStressTest.kt

-73
This file was deleted.

0 commit comments

Comments
 (0)