@@ -23,7 +23,7 @@ class LimitedParallelismStressTest(private val targetParallelism: Int) : TestBas
23
23
24
24
@get:Rule
25
25
val executor = ExecutorRule (targetParallelism * 2 )
26
- private val iterations = 100_000 * stressTestMultiplier
26
+ private val iterations = 100_000
27
27
28
28
private val parallelism = AtomicInteger (0 )
29
29
@@ -37,27 +37,31 @@ class LimitedParallelismStressTest(private val targetParallelism: Int) : TestBas
37
37
@Test
38
38
fun testLimitedExecutor () = runTest {
39
39
val view = executor.limitedParallelism(targetParallelism)
40
- repeat(iterations) {
41
- launch(view) {
42
- checkParallelism()
40
+ doStress {
41
+ repeat(iterations) {
42
+ launch(view) {
43
+ checkParallelism()
44
+ }
43
45
}
44
46
}
45
47
}
46
48
47
49
@Test
48
50
fun testLimitedDispatchersIo () = runTest {
49
51
val view = Dispatchers .IO .limitedParallelism(targetParallelism)
50
- repeat(iterations) {
51
- launch(view) {
52
- checkParallelism()
52
+ doStress {
53
+ repeat(iterations) {
54
+ launch(view) {
55
+ checkParallelism()
56
+ }
53
57
}
54
58
}
55
59
}
56
60
57
61
@Test
58
62
fun testLimitedDispatchersIoDispatchYield () = runTest {
59
63
val view = Dispatchers .IO .limitedParallelism(targetParallelism)
60
- repeat(iterations) {
64
+ doStress {
61
65
launch(view) {
62
66
yield ()
63
67
checkParallelism()
@@ -68,16 +72,26 @@ class LimitedParallelismStressTest(private val targetParallelism: Int) : TestBas
68
72
@Test
69
73
fun testLimitedExecutorReachesTargetParallelism () = runTest {
70
74
val view = executor.limitedParallelism(targetParallelism)
71
- repeat(iterations) {
72
- val barrier = CyclicBarrier (targetParallelism + 1 )
73
- repeat(targetParallelism) {
74
- launch(view) {
75
- barrier.await()
75
+ doStress {
76
+ repeat(iterations) {
77
+ val barrier = CyclicBarrier (targetParallelism + 1 )
78
+ repeat(targetParallelism) {
79
+ launch(view) {
80
+ barrier.await()
81
+ }
76
82
}
83
+ // Successfully awaited parallelism + 1
84
+ barrier.await()
85
+ coroutineContext.job.children.toList().joinAll()
86
+ }
87
+ }
88
+ }
89
+
90
+ private suspend inline fun doStress (crossinline block : suspend CoroutineScope .() -> Unit ) {
91
+ repeat(stressTestMultiplier) {
92
+ coroutineScope {
93
+ block()
77
94
}
78
- // Successfully awaited parallelism + 1
79
- barrier.await()
80
- coroutineContext.job.children.toList().joinAll()
81
95
}
82
96
}
83
97
}
0 commit comments