Skip to content

Commit c4a6ae1

Browse files
authored
Take number of CPU cores into account in BlockingCoroutineDispatcherTest (#2737)
1 parent 119e443 commit c4a6ae1

File tree

2 files changed

+2
-10
lines changed

2 files changed

+2
-10
lines changed

kotlinx-coroutines-core/jvm/test/scheduling/BlockingCoroutineDispatcherTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class BlockingCoroutineDispatcherTest : SchedulerTestBase() {
101101
firstBarrier.await()
102102
secondBarrier.await()
103103
blockingTasks.joinAll()
104-
checkPoolThreadsCreated(21..22)
104+
checkPoolThreadsCreated(21 /* blocking tasks + 1 for CPU */..20 + CORES_COUNT)
105105
}
106106

107107
@Test
@@ -122,7 +122,7 @@ class BlockingCoroutineDispatcherTest : SchedulerTestBase() {
122122
barrier.await()
123123
blockingTasks.joinAll()
124124
// There may be race when multiple CPU threads are trying to lazily created one more
125-
checkPoolThreadsCreated(104..120)
125+
checkPoolThreadsCreated(101..100 + CORES_COUNT)
126126
}
127127

128128
@Test

kotlinx-coroutines-core/jvm/test/scheduling/SchedulerTestBase.kt

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,6 @@ abstract class SchedulerTestBase : TestBase() {
3939
)
4040
}
4141

42-
/**
43-
* Asserts that any number of pool worker threads in [range] exists at the time of method invocation
44-
*/
45-
fun checkPoolThreadsExist(range: IntRange) {
46-
val threads = Thread.getAllStackTraces().keys.asSequence().filter { it is CoroutineScheduler.Worker }.count()
47-
assertTrue(threads in range, "Expected threads in $range interval, but has $threads")
48-
}
49-
5042
private fun maxSequenceNumber(): Int? {
5143
return Thread.getAllStackTraces().keys.asSequence().filter { it is CoroutineScheduler.Worker }
5244
.map { sequenceNumber(it.name) }.maxOrNull()

0 commit comments

Comments
 (0)