Skip to content

Commit

Permalink
Update lincheck to 2.5.3 and re-write the corresponding tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ndkoval authored and elizarov committed Dec 26, 2019
1 parent 1f77783 commit 4f24a7a
Show file tree
Hide file tree
Showing 15 changed files with 342 additions and 515 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ allprojects {
kotlin_version = rootProject.properties['kotlin_snapshot_version']
}

if (build_snapshot_train || atomicfu_version.endsWith("-SNAPSHOT")) {
if (build_snapshot_train || atomicfu_version.endsWith("-SNAPSHOT") || lincheck_version.endsWith("-SNAPSHOT")) {
repositories {
mavenLocal()
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ kotlin_version=1.3.61
junit_version=4.12
atomicfu_version=0.14.1
html_version=0.6.8
lincheck_version=2.0
lincheck_version=2.5.3
dokka_version=0.9.16-rdev-2-mpp-hacks
byte_buddy_version=1.9.3
reactor_vesion=3.2.5.RELEASE
Expand Down
2 changes: 1 addition & 1 deletion kotlinx-coroutines-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ configurations {

kotlin.sourceSets {
jvmTest.dependencies {
api "com.devexperts.lincheck:lincheck:$lincheck_version"
api "org.jetbrains.kotlinx:lincheck:$lincheck_version"
api "com.esotericsoftware:kryo:4.0.0"
implementation project (":android-unit-tests")
}
Expand Down
55 changes: 18 additions & 37 deletions kotlinx-coroutines-core/common/test/channels/TestChannelKind.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,45 +7,26 @@ package kotlinx.coroutines.channels
import kotlinx.coroutines.*
import kotlinx.coroutines.selects.*

enum class TestChannelKind {
RENDEZVOUS {
override fun create(): Channel<Int> = Channel(Channel.RENDEZVOUS)
override fun toString(): String = "RendezvousChannel"
},
ARRAY_1 {
override fun create(): Channel<Int> = Channel(1)
override fun toString(): String = "ArrayChannel(1)"
},
ARRAY_10 {
override fun create(): Channel<Int> = Channel(10)
override fun toString(): String = "ArrayChannel(10)"
},
LINKED_LIST {
override fun create(): Channel<Int> = Channel(Channel.UNLIMITED)
override fun toString(): String = "LinkedListChannel"
},
CONFLATED {
override fun create(): Channel<Int> = Channel(Channel.CONFLATED)
override fun toString(): String = "ConflatedChannel"
override val isConflated: Boolean get() = true
},
ARRAY_BROADCAST_1 {
override fun create(): Channel<Int> = ChannelViaBroadcast(BroadcastChannel(1))
override fun toString(): String = "ArrayBroadcastChannel(1)"
},
ARRAY_BROADCAST_10 {
override fun create(): Channel<Int> = ChannelViaBroadcast(BroadcastChannel(10))
override fun toString(): String = "ArrayBroadcastChannel(10)"
},
CONFLATED_BROADCAST {
override fun create(): Channel<Int> = ChannelViaBroadcast(ConflatedBroadcastChannel<Int>())
override fun toString(): String = "ConflatedBroadcastChannel"
override val isConflated: Boolean get() = true
}
enum class TestChannelKind(val capacity: Int,
private val description: String,
private val viaBroadcast: Boolean = false
) {
RENDEZVOUS(0, "RendezvousChannel"),
ARRAY_1(1, "ArrayChannel(1)"),
ARRAY_2(2, "ArrayChannel(2)"),
ARRAY_10(10, "ArrayChannel(10)"),
LINKED_LIST(Channel.UNLIMITED, "LinkedListChannel"),
CONFLATED(Channel.CONFLATED, "ConflatedChannel"),
ARRAY_1_BROADCAST(1, "ArrayBroadcastChannel(1)", viaBroadcast = true),
ARRAY_10_BROADCAST(10, "ArrayBroadcastChannel(10)", viaBroadcast = true),
CONFLATED_BROADCAST(Channel.CONFLATED, "ConflatedBroadcastChannel", viaBroadcast = true)
;

abstract fun create(): Channel<Int>
open val isConflated: Boolean get() = false
fun create(): Channel<Int> = if (viaBroadcast) ChannelViaBroadcast(BroadcastChannel(capacity))
else Channel(capacity)

val isConflated get() = capacity == Channel.CONFLATED
override fun toString(): String = description
}

private class ChannelViaBroadcast<E>(
Expand Down
20 changes: 20 additions & 0 deletions kotlinx-coroutines-core/jvm/test/LCStressOptionsDefault.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright 2016-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/
package kotlinx.coroutines

import org.jetbrains.kotlinx.lincheck.*
import org.jetbrains.kotlinx.lincheck.strategy.stress.*
import kotlin.reflect.*

class LCStressOptionsDefault : StressOptions() {
init {
iterations(100 * stressTestMultiplierCbrt)
invocationsPerIteration(1000 * stressTestMultiplierCbrt)
actorsBefore(if (isStressTest) 3 else 0)
threads(3)
actorsPerThread(if (isStressTest) 3 else 2)
}
}

fun Options<*,*>.check(testClass: KClass<*>) = LinChecker.check(testClass.java, this)
4 changes: 4 additions & 0 deletions kotlinx-coroutines-core/jvm/test/TestBase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ package kotlinx.coroutines
import kotlinx.coroutines.internal.*
import kotlinx.coroutines.scheduling.*
import org.junit.*
import java.lang.Math.*
import java.util.*
import java.util.concurrent.atomic.*
import kotlin.coroutines.*
import kotlin.math.*
import kotlin.test.*

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

public val stressTestMultiplierCbrt = cbrt(stressTestMultiplier.toDouble()).roundToInt()

/**
* Base class for tests, so that tests for predictable scheduling of actions in multiple coroutines sharing a single
* thread can be written. Use it like this:
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit 4f24a7a

Please sign in to comment.