Skip to content

Reduce the overall time spent on stress tests in stress mode #3890

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<Long>()
val sender =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down
8 changes: 4 additions & 4 deletions kotlinx-coroutines-core/jvm/test/AbstractLincheckTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Array<Any>> =
TestBroadcastChannelKind.values().map { arrayOf<Any>(it) }
TestBroadcastChannelKind.entries.map { arrayOf<Any>(it) }
}

private val nReceivers = if (isStressTest) 10 else 5
private val nSeconds = 3 * stressTestMultiplier
private val nSeconds = 3 * stressTestMultiplierSqrt

private val broadcast = kind.create<Long>()
private val pool = newFixedThreadPoolContext(nReceivers + 1, "BroadcastChannelMultiReceiveStressTest")
Expand Down Expand Up @@ -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()
Expand All @@ -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
Expand All @@ -116,8 +118,9 @@ class BroadcastChannelMultiReceiveStressTest(
try {
val stop = doReceived(receiverIndex, channel.receive())
if (stop) break
} catch (ex: ClosedReceiveChannelException) {
break
}
catch (ex: ClosedReceiveChannelException) { break }
}
}

Expand All @@ -141,7 +144,9 @@ class BroadcastChannelMultiReceiveStressTest(
val event = select<Long> { channel.onReceive { it } }
val stop = doReceived(receiverIndex, event)
if (stop) break
} catch (ex: ClosedReceiveChannelException) { break }
} catch (ex: ClosedReceiveChannelException) {
break
}
}
}

Expand All @@ -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?)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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() }
Expand Down Expand Up @@ -59,4 +59,4 @@ class SelectPhilosophersStressTest : TestBase() {
assertTrue(eats > 0, "$id shall not starve")
}
}
}
}