diff --git a/kotlinx-coroutines-core/concurrent/test/channels/BroadcastChannelSubStressTest.kt b/kotlinx-coroutines-core/concurrent/test/channels/BroadcastChannelSubStressTest.kt index 8f6a8e0c31..8db6d8b9ec 100644 --- a/kotlinx-coroutines-core/concurrent/test/channels/BroadcastChannelSubStressTest.kt +++ b/kotlinx-coroutines-core/concurrent/test/channels/BroadcastChannelSubStressTest.kt @@ -12,13 +12,13 @@ import kotlin.test.* */ class BroadcastChannelSubStressTest: TestBase() { - private val nSeconds = 5 * stressTestMultiplier + private val nSeconds = maxOf(5, stressTestMultiplier) private val sentTotal = atomic(0L) private val receivedTotal = atomic(0L) @Test fun testStress() = runTest { - TestBroadcastChannelKind.values().forEach { kind -> + TestBroadcastChannelKind.entries.forEach { kind -> println("--- BroadcastChannelSubStressTest $kind") val broadcast = kind.create() val sender = diff --git a/kotlinx-coroutines-core/concurrent/test/sync/MutexStressTest.kt b/kotlinx-coroutines-core/concurrent/test/sync/MutexStressTest.kt index 8c8f04f809..67ff03b91e 100644 --- a/kotlinx-coroutines-core/concurrent/test/sync/MutexStressTest.kt +++ b/kotlinx-coroutines-core/concurrent/test/sync/MutexStressTest.kt @@ -8,7 +8,7 @@ import kotlin.test.* class MutexStressTest : TestBase() { - private val n = (if (isNative) 1_000 else 10_000) * stressTestMultiplier + private val n = 1000 * stressTestMultiplier // It mostly stresses K/N as JVM Mutex is tested by lincheck @Test fun testDefaultDispatcher() = runTest { testBody(Dispatchers.Default) } diff --git a/kotlinx-coroutines-core/jvm/test/AbstractLincheckTest.kt b/kotlinx-coroutines-core/jvm/test/AbstractLincheckTest.kt index 4cb45ba96e..6287be0081 100644 --- a/kotlinx-coroutines-core/jvm/test/AbstractLincheckTest.kt +++ b/kotlinx-coroutines-core/jvm/test/AbstractLincheckTest.kt @@ -13,16 +13,16 @@ abstract class AbstractLincheckTest { @Test fun modelCheckingTest() = ModelCheckingOptions() - .iterations(if (isStressTest) 200 else 20) - .invocationsPerIteration(if (isStressTest) 10_000 else 1_000) + .iterations(20 * stressTestMultiplierSqrt) + .invocationsPerIteration(1_000 * stressTestMultiplierSqrt) .commonConfiguration() .customize(isStressTest) .check(this::class) @Test fun stressTest() = StressOptions() - .iterations(if (isStressTest) 200 else 20) - .invocationsPerIteration(if (isStressTest) 10_000 else 1_000) + .iterations(20 * stressTestMultiplierSqrt) + .invocationsPerIteration(1_000 * stressTestMultiplierSqrt) .commonConfiguration() .customize(isStressTest) .check(this::class) diff --git a/kotlinx-coroutines-core/jvm/test/channels/BroadcastChannelMultiReceiveStressTest.kt b/kotlinx-coroutines-core/jvm/test/channels/BroadcastChannelMultiReceiveStressTest.kt index e6e629da22..5b211807da 100644 --- a/kotlinx-coroutines-core/jvm/test/channels/BroadcastChannelMultiReceiveStressTest.kt +++ b/kotlinx-coroutines-core/jvm/test/channels/BroadcastChannelMultiReceiveStressTest.kt @@ -15,15 +15,17 @@ import java.util.concurrent.atomic.* class BroadcastChannelMultiReceiveStressTest( private val kind: TestBroadcastChannelKind ) : TestBase() { + + // Stressed by lincheck companion object { @Parameterized.Parameters(name = "{0}") @JvmStatic fun params(): Collection> = - TestBroadcastChannelKind.values().map { arrayOf(it) } + TestBroadcastChannelKind.entries.map { arrayOf(it) } } private val nReceivers = if (isStressTest) 10 else 5 - private val nSeconds = 3 * stressTestMultiplier + private val nSeconds = 3 * stressTestMultiplierSqrt private val broadcast = kind.create() private val pool = newFixedThreadPoolContext(nReceivers + 1, "BroadcastChannelMultiReceiveStressTest") @@ -62,13 +64,13 @@ class BroadcastChannelMultiReceiveStressTest( println("Launching $name") receivers += launch(pool + CoroutineName(name)) { val channel = broadcast.openSubscription() - when (receiverIndex % 5) { - 0 -> doReceive(channel, receiverIndex) - 1 -> doReceiveCatching(channel, receiverIndex) - 2 -> doIterator(channel, receiverIndex) - 3 -> doReceiveSelect(channel, receiverIndex) - 4 -> doReceiveCatchingSelect(channel, receiverIndex) - } + when (receiverIndex % 5) { + 0 -> doReceive(channel, receiverIndex) + 1 -> doReceiveCatching(channel, receiverIndex) + 2 -> doIterator(channel, receiverIndex) + 3 -> doReceiveSelect(channel, receiverIndex) + 4 -> doReceiveCatchingSelect(channel, receiverIndex) + } channel.cancel() } printProgress() @@ -93,7 +95,7 @@ class BroadcastChannelMultiReceiveStressTest( } catch (e: Exception) { println("Failed: $e") pool.dumpThreads("Threads in pool") - receivers.indices.forEach { index -> + receivers.indices.forEach { index -> println("lastReceived[$index] = ${lastReceived[index].get()}") } throw e @@ -116,8 +118,9 @@ class BroadcastChannelMultiReceiveStressTest( try { val stop = doReceived(receiverIndex, channel.receive()) if (stop) break + } catch (ex: ClosedReceiveChannelException) { + break } - catch (ex: ClosedReceiveChannelException) { break } } } @@ -141,7 +144,9 @@ class BroadcastChannelMultiReceiveStressTest( val event = select { channel.onReceive { it } } val stop = doReceived(receiverIndex, event) if (stop) break - } catch (ex: ClosedReceiveChannelException) { break } + } catch (ex: ClosedReceiveChannelException) { + break + } } } @@ -152,4 +157,10 @@ class BroadcastChannelMultiReceiveStressTest( if (stop) break } } + + @Suppress("UNUSED_PARAMETER") + private fun println(debugMessage: String) { + // Uncomment for local debugging + //println(debugMessage as Any?) + } } diff --git a/kotlinx-coroutines-core/jvm/test/selects/SelectPhilosophersStressTest.kt b/kotlinx-coroutines-core/jvm/test/selects/SelectPhilosophersStressTest.kt index 09918068de..423c1a8a55 100644 --- a/kotlinx-coroutines-core/jvm/test/selects/SelectPhilosophersStressTest.kt +++ b/kotlinx-coroutines-core/jvm/test/selects/SelectPhilosophersStressTest.kt @@ -7,7 +7,7 @@ import org.junit.Test import kotlin.test.* class SelectPhilosophersStressTest : TestBase() { - private val TEST_DURATION = 3000L * stressTestMultiplier + private val TEST_DURATION = 3000L * stressTestMultiplierSqrt val n = 10 // number of philosophers private val forks = Array(n) { Mutex() } @@ -59,4 +59,4 @@ class SelectPhilosophersStressTest : TestBase() { assertTrue(eats > 0, "$id shall not starve") } } -} \ No newline at end of file +}