Skip to content

Commit 21ce9c0

Browse files
committed
Additional debug output for CoroutineSchedulerStressTest
1 parent e051c33 commit 21ce9c0

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

core/kotlinx-coroutines-core/test/scheduling/CoroutineSchedulerStressTest.kt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package kotlinx.coroutines.experimental.scheduling
66

77
import kotlinx.coroutines.experimental.*
8+
import kotlinx.coroutines.experimental.internal.*
89
import kotlinx.coroutines.experimental.scheduling.SchedulerTestBase.Companion.checkPoolThreadsCreated
910
import org.junit.*
1011
import org.junit.Test
@@ -14,14 +15,13 @@ import kotlin.coroutines.experimental.*
1415
import kotlin.test.*
1516

1617
class CoroutineSchedulerStressTest : TestBase() {
17-
1818
private var dispatcher: ExperimentalCoroutineDispatcher = ExperimentalCoroutineDispatcher()
1919
private val observedThreads = ConcurrentHashMap<Thread, Long>()
2020
private val tasksNum = 2_000_000 * stressMemoryMultiplier()
2121

2222
private fun stressMemoryMultiplier(): Int {
2323
return if (isStressTest) {
24-
Runtime.getRuntime().availableProcessors() * 4
24+
AVAILABLE_PROCESSORS * 4
2525
} else {
2626
1
2727
}
@@ -81,7 +81,7 @@ class CoroutineSchedulerStressTest : TestBase() {
8181

8282
private fun stressTest(submissionInitiator: CoroutineDispatcher) {
8383
/*
84-
* Run 1 million tasks and validate that
84+
* Run 2 million tasks and validate that
8585
* 1) All of them are completed successfully
8686
* 2) Every thread executed task at least once
8787
*/
@@ -94,7 +94,9 @@ class CoroutineSchedulerStressTest : TestBase() {
9494
})
9595

9696
finishLatch.await()
97-
assertTrue(Runtime.getRuntime().availableProcessors() in (observedThreads.size - 1)..observedThreads.size)
97+
val n = observedThreads.size
98+
println("Observed $n threads with $AVAILABLE_PROCESSORS available processors")
99+
assertTrue(AVAILABLE_PROCESSORS in (n - 1)..n)
98100
validateResults()
99101
}
100102

@@ -110,7 +112,6 @@ class CoroutineSchedulerStressTest : TestBase() {
110112
private fun validateResults() {
111113
val result = observedThreads.values.sum()
112114
assertEquals(tasksNum.toLong(), result)
113-
checkPoolThreadsCreated(Runtime.getRuntime().availableProcessors())
115+
checkPoolThreadsCreated(AVAILABLE_PROCESSORS)
114116
}
115-
116117
}

0 commit comments

Comments
 (0)