5
5
package kotlinx.coroutines.experimental.scheduling
6
6
7
7
import kotlinx.coroutines.experimental.*
8
+ import kotlinx.coroutines.experimental.internal.*
8
9
import kotlinx.coroutines.experimental.scheduling.SchedulerTestBase.Companion.checkPoolThreadsCreated
9
10
import org.junit.*
10
11
import org.junit.Test
@@ -14,14 +15,13 @@ import kotlin.coroutines.experimental.*
14
15
import kotlin.test.*
15
16
16
17
class CoroutineSchedulerStressTest : TestBase () {
17
-
18
18
private var dispatcher: ExperimentalCoroutineDispatcher = ExperimentalCoroutineDispatcher ()
19
19
private val observedThreads = ConcurrentHashMap <Thread , Long >()
20
20
private val tasksNum = 2_000_000 * stressMemoryMultiplier()
21
21
22
22
private fun stressMemoryMultiplier (): Int {
23
23
return if (isStressTest) {
24
- Runtime .getRuntime().availableProcessors() * 4
24
+ AVAILABLE_PROCESSORS * 4
25
25
} else {
26
26
1
27
27
}
@@ -81,7 +81,7 @@ class CoroutineSchedulerStressTest : TestBase() {
81
81
82
82
private fun stressTest (submissionInitiator : CoroutineDispatcher ) {
83
83
/*
84
- * Run 1 million tasks and validate that
84
+ * Run 2 million tasks and validate that
85
85
* 1) All of them are completed successfully
86
86
* 2) Every thread executed task at least once
87
87
*/
@@ -94,7 +94,9 @@ class CoroutineSchedulerStressTest : TestBase() {
94
94
})
95
95
96
96
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)
98
100
validateResults()
99
101
}
100
102
@@ -110,7 +112,6 @@ class CoroutineSchedulerStressTest : TestBase() {
110
112
private fun validateResults () {
111
113
val result = observedThreads.values.sum()
112
114
assertEquals(tasksNum.toLong(), result)
113
- checkPoolThreadsCreated(Runtime .getRuntime().availableProcessors() )
115
+ checkPoolThreadsCreated(AVAILABLE_PROCESSORS )
114
116
}
115
-
116
117
}
0 commit comments