Skip to content

Commit 3561c13

Browse files
committed
Add tests for runBlocking with LimitedDispatcher
1 parent adbb5b4 commit 3561c13

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package scheduling
2+
3+
import kotlinx.coroutines.testing.*
4+
import org.junit.*
5+
import org.junit.runner.*
6+
import org.junit.runners.*
7+
8+
@RunWith(Parameterized::class)
9+
class RunBlockingLimitedDispatcherLivenessStressTest(private val yieldMask: Int) : RunBlockingCoroutineSchedulerLivenessTestBase() {
10+
init {
11+
corePoolSize = 1
12+
}
13+
14+
companion object {
15+
@JvmStatic
16+
@Parameterized.Parameters
17+
fun data(): Array<Array<Any?>> {
18+
return Array(32 * stressTestMultiplierSqrt) { arrayOf(it) }
19+
}
20+
}
21+
22+
@Test
23+
fun testLivenessOfLimitedDispatcherOnTopOfDefaultDispatcher() =
24+
testSchedulerLiveness(dispatcher.limitedParallelism(1), yieldMask)
25+
26+
@Test
27+
fun testLivenessOfLimitedDispatcherOnTopOfIoDispatcher() = testSchedulerLiveness(
28+
// Important: inner limitedDispatcher will be on top of this LimitedDispatcher, so there are two Workers from
29+
// two different LimitedDispatchers that must coordinate their permits, not just one.
30+
// In other words, LimitedDispatcher's Worker should also respect BlockingDispatchAware on its inner tasks
31+
blockingDispatcher.value.limitedParallelism(1), yieldMask
32+
)
33+
}

0 commit comments

Comments
 (0)