Skip to content

Commit d9fe422

Browse files
committed
Reduce the number of iterations and time spent in [nowadays] less relevant tests
1 parent d3aef52 commit d9fe422

File tree

4 files changed

+28
-17
lines changed

4 files changed

+28
-17
lines changed

kotlinx-coroutines-core/concurrent/test/channels/BroadcastChannelSubStressTest.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ import kotlin.test.*
1212
*/
1313
class BroadcastChannelSubStressTest: TestBase() {
1414

15-
private val nSeconds = 5 * stressTestMultiplier
15+
private val nSeconds = maxOf(5, stressTestMultiplier)
1616
private val sentTotal = atomic(0L)
1717
private val receivedTotal = atomic(0L)
1818

1919
@Test
2020
fun testStress() = runTest {
21-
TestBroadcastChannelKind.values().forEach { kind ->
21+
TestBroadcastChannelKind.entries.forEach { kind ->
2222
println("--- BroadcastChannelSubStressTest $kind")
2323
val broadcast = kind.create<Long>()
2424
val sender =

kotlinx-coroutines-core/concurrent/test/sync/MutexStressTest.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import kotlin.test.*
88

99
class MutexStressTest : TestBase() {
1010

11-
private val n = (if (isNative) 1_000 else 10_000) * stressTestMultiplier
11+
private val n = 1000 * stressTestMultiplier // It mostly stresses K/N as JVM Mutex is tested by lincheck
1212

1313
@Test
1414
fun testDefaultDispatcher() = runTest { testBody(Dispatchers.Default) }

kotlinx-coroutines-core/jvm/test/channels/BroadcastChannelMultiReceiveStressTest.kt

+23-12
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,17 @@ import java.util.concurrent.atomic.*
1515
class BroadcastChannelMultiReceiveStressTest(
1616
private val kind: TestBroadcastChannelKind
1717
) : TestBase() {
18+
19+
// Stressed by lincheck
1820
companion object {
1921
@Parameterized.Parameters(name = "{0}")
2022
@JvmStatic
2123
fun params(): Collection<Array<Any>> =
22-
TestBroadcastChannelKind.values().map { arrayOf<Any>(it) }
24+
TestBroadcastChannelKind.entries.map { arrayOf<Any>(it) }
2325
}
2426

2527
private val nReceivers = if (isStressTest) 10 else 5
26-
private val nSeconds = 3 * stressTestMultiplier
28+
private val nSeconds = 3 * stressTestMultiplierSqrt
2729

2830
private val broadcast = kind.create<Long>()
2931
private val pool = newFixedThreadPoolContext(nReceivers + 1, "BroadcastChannelMultiReceiveStressTest")
@@ -62,13 +64,13 @@ class BroadcastChannelMultiReceiveStressTest(
6264
println("Launching $name")
6365
receivers += launch(pool + CoroutineName(name)) {
6466
val channel = broadcast.openSubscription()
65-
when (receiverIndex % 5) {
66-
0 -> doReceive(channel, receiverIndex)
67-
1 -> doReceiveCatching(channel, receiverIndex)
68-
2 -> doIterator(channel, receiverIndex)
69-
3 -> doReceiveSelect(channel, receiverIndex)
70-
4 -> doReceiveCatchingSelect(channel, receiverIndex)
71-
}
67+
when (receiverIndex % 5) {
68+
0 -> doReceive(channel, receiverIndex)
69+
1 -> doReceiveCatching(channel, receiverIndex)
70+
2 -> doIterator(channel, receiverIndex)
71+
3 -> doReceiveSelect(channel, receiverIndex)
72+
4 -> doReceiveCatchingSelect(channel, receiverIndex)
73+
}
7274
channel.cancel()
7375
}
7476
printProgress()
@@ -93,7 +95,7 @@ class BroadcastChannelMultiReceiveStressTest(
9395
} catch (e: Exception) {
9496
println("Failed: $e")
9597
pool.dumpThreads("Threads in pool")
96-
receivers.indices.forEach { index ->
98+
receivers.indices.forEach { index ->
9799
println("lastReceived[$index] = ${lastReceived[index].get()}")
98100
}
99101
throw e
@@ -116,8 +118,9 @@ class BroadcastChannelMultiReceiveStressTest(
116118
try {
117119
val stop = doReceived(receiverIndex, channel.receive())
118120
if (stop) break
121+
} catch (ex: ClosedReceiveChannelException) {
122+
break
119123
}
120-
catch (ex: ClosedReceiveChannelException) { break }
121124
}
122125
}
123126

@@ -141,7 +144,9 @@ class BroadcastChannelMultiReceiveStressTest(
141144
val event = select<Long> { channel.onReceive { it } }
142145
val stop = doReceived(receiverIndex, event)
143146
if (stop) break
144-
} catch (ex: ClosedReceiveChannelException) { break }
147+
} catch (ex: ClosedReceiveChannelException) {
148+
break
149+
}
145150
}
146151
}
147152

@@ -152,4 +157,10 @@ class BroadcastChannelMultiReceiveStressTest(
152157
if (stop) break
153158
}
154159
}
160+
161+
@Suppress("UNUSED_PARAMETER")
162+
private fun println(debugMessage: String) {
163+
// Uncomment for local debugging
164+
// kotlin.io.println(debugMessage)
165+
}
155166
}

kotlinx-coroutines-core/jvm/test/selects/SelectPhilosophersStressTest.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import org.junit.Test
77
import kotlin.test.*
88

99
class SelectPhilosophersStressTest : TestBase() {
10-
private val TEST_DURATION = 3000L * stressTestMultiplier
10+
private val TEST_DURATION = 3000L * stressTestMultiplierSqrt
1111

1212
val n = 10 // number of philosophers
1313
private val forks = Array(n) { Mutex() }
@@ -59,4 +59,4 @@ class SelectPhilosophersStressTest : TestBase() {
5959
assertTrue(eats > 0, "$id shall not starve")
6060
}
6161
}
62-
}
62+
}

0 commit comments

Comments
 (0)