Fixed ConflatedChannelCloseStressTest on low-core machines
diff --git a/kotlinx-coroutines-core/src/test/kotlin/kotlinx/coroutines/experimental/channels/ConflatedChannelCloseStressTest.kt b/kotlinx-coroutines-core/src/test/kotlin/kotlinx/coroutines/experimental/channels/ConflatedChannelCloseStressTest.kt
index 2655a52..9f135c0 100644
--- a/kotlinx-coroutines-core/src/test/kotlin/kotlinx/coroutines/experimental/channels/ConflatedChannelCloseStressTest.kt
+++ b/kotlinx-coroutines-core/src/test/kotlin/kotlinx/coroutines/experimental/channels/ConflatedChannelCloseStressTest.kt
@@ -19,6 +19,7 @@
import junit.framework.Assert.assertTrue
import junit.framework.Assert.fail
import kotlinx.coroutines.experimental.*
+import org.junit.After
import org.junit.Test
import java.util.concurrent.atomic.AtomicInteger
import java.util.concurrent.atomic.AtomicReference
@@ -33,11 +34,16 @@
val closed = AtomicInteger()
val received = AtomicInteger()
+ val pool = newFixedThreadPoolContext(nSenders + 2, "TestStressClose")
+
+ @After
+ fun tearDown() { pool[Job]!!.cancel() }
+
@Test
fun testStressClose() = runBlocking<Unit> {
val senderJobs = List(nSenders) { Job() }
val senders = List(nSenders) { senderId ->
- launch(CommonPool) {
+ launch(pool) {
var x = senderId
try {
while (isActive) {
@@ -55,7 +61,7 @@
}
}
val closerJob = Job()
- val closer = launch(CommonPool) {
+ val closer = launch(pool) {
try {
while (isActive) {
flipChannel()
@@ -66,7 +72,7 @@
closerJob.cancel()
}
}
- val receiver = async(CommonPool) {
+ val receiver = async(pool) {
while (isActive) {
curChannel.get().receiveOrNull()
received.incrementAndGet()