Skip to content

Commit 656bcd9

Browse files
committed
Fixed ConflatedChannelCloseStressTest on low-core machines
1 parent 98b7a6e commit 656bcd9

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

kotlinx-coroutines-core/src/test/kotlin/kotlinx/coroutines/experimental/channels/ConflatedChannelCloseStressTest.kt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package kotlinx.coroutines.experimental.channels
1919
import junit.framework.Assert.assertTrue
2020
import junit.framework.Assert.fail
2121
import kotlinx.coroutines.experimental.*
22+
import org.junit.After
2223
import org.junit.Test
2324
import java.util.concurrent.atomic.AtomicInteger
2425
import java.util.concurrent.atomic.AtomicReference
@@ -33,11 +34,16 @@ class ConflatedChannelCloseStressTest : TestBase() {
3334
val closed = AtomicInteger()
3435
val received = AtomicInteger()
3536

37+
val pool = newFixedThreadPoolContext(nSenders + 2, "TestStressClose")
38+
39+
@After
40+
fun tearDown() { pool[Job]!!.cancel() }
41+
3642
@Test
3743
fun testStressClose() = runBlocking<Unit> {
3844
val senderJobs = List(nSenders) { Job() }
3945
val senders = List(nSenders) { senderId ->
40-
launch(CommonPool) {
46+
launch(pool) {
4147
var x = senderId
4248
try {
4349
while (isActive) {
@@ -55,7 +61,7 @@ class ConflatedChannelCloseStressTest : TestBase() {
5561
}
5662
}
5763
val closerJob = Job()
58-
val closer = launch(CommonPool) {
64+
val closer = launch(pool) {
5965
try {
6066
while (isActive) {
6167
flipChannel()
@@ -66,7 +72,7 @@ class ConflatedChannelCloseStressTest : TestBase() {
6672
closerJob.cancel()
6773
}
6874
}
69-
val receiver = async(CommonPool) {
75+
val receiver = async(pool) {
7076
while (isActive) {
7177
curChannel.get().receiveOrNull()
7278
received.incrementAndGet()

0 commit comments

Comments
 (0)