Skip to content

Commit 6d15b81

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

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
@@ -15,13 +15,13 @@ import kotlin.test.*
1515
*/
1616
class BroadcastChannelSubStressTest: TestBase() {
1717

18-
private val nSeconds = 5 * stressTestMultiplier
18+
private val nSeconds = maxOf(5, stressTestMultiplier)
1919
private val sentTotal = atomic(0L)
2020
private val receivedTotal = atomic(0L)
2121

2222
@Test
2323
fun testStress() = runTest {
24-
TestBroadcastChannelKind.values().forEach { kind ->
24+
TestBroadcastChannelKind.entries.forEach { kind ->
2525
println("--- BroadcastChannelSubStressTest $kind")
2626
val broadcast = kind.create<Long>()
2727
val sender =

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

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

1212
class MutexStressTest : TestBase() {
1313

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

1616
@Test
1717
fun testDefaultDispatcher() = runTest { testBody(Dispatchers.Default) }

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

+23-12
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,17 @@ import java.util.concurrent.atomic.*
1818
class BroadcastChannelMultiReceiveStressTest(
1919
private val kind: TestBroadcastChannelKind
2020
) : TestBase() {
21+
22+
// Stressed by lincheck
2123
companion object {
2224
@Parameterized.Parameters(name = "{0}")
2325
@JvmStatic
2426
fun params(): Collection<Array<Any>> =
25-
TestBroadcastChannelKind.values().map { arrayOf<Any>(it) }
27+
TestBroadcastChannelKind.entries.map { arrayOf<Any>(it) }
2628
}
2729

2830
private val nReceivers = if (isStressTest) 10 else 5
29-
private val nSeconds = 3 * stressTestMultiplier
31+
private val nSeconds = 3 * stressTestMultiplierSqrt
3032

3133
private val broadcast = kind.create<Long>()
3234
private val pool = newFixedThreadPoolContext(nReceivers + 1, "BroadcastChannelMultiReceiveStressTest")
@@ -65,13 +67,13 @@ class BroadcastChannelMultiReceiveStressTest(
6567
println("Launching $name")
6668
receivers += launch(pool + CoroutineName(name)) {
6769
val channel = broadcast.openSubscription()
68-
when (receiverIndex % 5) {
69-
0 -> doReceive(channel, receiverIndex)
70-
1 -> doReceiveCatching(channel, receiverIndex)
71-
2 -> doIterator(channel, receiverIndex)
72-
3 -> doReceiveSelect(channel, receiverIndex)
73-
4 -> doReceiveCatchingSelect(channel, receiverIndex)
74-
}
70+
when (receiverIndex % 5) {
71+
0 -> doReceive(channel, receiverIndex)
72+
1 -> doReceiveCatching(channel, receiverIndex)
73+
2 -> doIterator(channel, receiverIndex)
74+
3 -> doReceiveSelect(channel, receiverIndex)
75+
4 -> doReceiveCatchingSelect(channel, receiverIndex)
76+
}
7577
channel.cancel()
7678
}
7779
printProgress()
@@ -96,7 +98,7 @@ class BroadcastChannelMultiReceiveStressTest(
9698
} catch (e: Exception) {
9799
println("Failed: $e")
98100
pool.dumpThreads("Threads in pool")
99-
receivers.indices.forEach { index ->
101+
receivers.indices.forEach { index ->
100102
println("lastReceived[$index] = ${lastReceived[index].get()}")
101103
}
102104
throw e
@@ -119,8 +121,9 @@ class BroadcastChannelMultiReceiveStressTest(
119121
try {
120122
val stop = doReceived(receiverIndex, channel.receive())
121123
if (stop) break
124+
} catch (ex: ClosedReceiveChannelException) {
125+
break
122126
}
123-
catch (ex: ClosedReceiveChannelException) { break }
124127
}
125128
}
126129

@@ -144,7 +147,9 @@ class BroadcastChannelMultiReceiveStressTest(
144147
val event = select<Long> { channel.onReceive { it } }
145148
val stop = doReceived(receiverIndex, event)
146149
if (stop) break
147-
} catch (ex: ClosedReceiveChannelException) { break }
150+
} catch (ex: ClosedReceiveChannelException) {
151+
break
152+
}
148153
}
149154
}
150155

@@ -155,4 +160,10 @@ class BroadcastChannelMultiReceiveStressTest(
155160
if (stop) break
156161
}
157162
}
163+
164+
@Suppress("UNUSED_PARAMETER")
165+
private fun println(debugMessage: String) {
166+
// Uncomment for local debugging
167+
// kotlin.io.println(debugMessage)
168+
}
158169
}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import org.junit.Test
1010
import kotlin.test.*
1111

1212
class SelectPhilosophersStressTest : TestBase() {
13-
private val TEST_DURATION = 3000L * stressTestMultiplier
13+
private val TEST_DURATION = 3000L * stressTestMultiplierSqrt
1414

1515
val n = 10 // number of philosophers
1616
private val forks = Array(n) { Mutex() }
@@ -62,4 +62,4 @@ class SelectPhilosophersStressTest : TestBase() {
6262
assertTrue(eats > 0, "$id shall not starve")
6363
}
6464
}
65-
}
65+
}

0 commit comments

Comments
 (0)