1
1
package scheduling
2
2
3
- import kotlinx.coroutines.*
4
- import kotlinx.coroutines.scheduling.*
5
3
import kotlinx.coroutines.testing.*
6
4
import org.junit.*
7
5
import org.junit.runner.*
8
6
import org.junit.runners.*
9
- import java.util.*
10
- import java.util.concurrent.*
11
7
12
8
@RunWith(Parameterized ::class )
13
- class RunBlockingDefaultDispatcherLivenessStressTest (private val yieldMask : Int ) : SchedulerTestBase () {
9
+ class RunBlockingDefaultDispatcherLivenessStressTest (private val yieldMask : Int ) : RunBlockingCoroutineSchedulerLivenessTestBase () {
14
10
init {
15
11
corePoolSize = 1
16
12
}
@@ -24,43 +20,5 @@ class RunBlockingDefaultDispatcherLivenessStressTest(private val yieldMask: Int)
24
20
}
25
21
26
22
@Test
27
- fun testLivenessOfDefaultDispatcher (): Unit = runBlocking {
28
- val oldRunBlockings = LinkedList <Job >()
29
- var maxOldRunBlockings = 0
30
- var busyWaits = 0
31
- repeat(5000 * stressTestMultiplierSqrt) {
32
- if (it % 1000 == 0 ) {
33
- System .err.println (" ======== $it , rb=${oldRunBlockings.size} , max rb=${maxOldRunBlockings} , busy=$busyWaits " )
34
- }
35
- val barrier = CyclicBarrier (2 )
36
- val barrier2 = CompletableDeferred <Unit >()
37
- val blocking = launch(dispatcher) {
38
- barrier.await()
39
- runBlocking {
40
- if ((yieldMask and 1 ) != 0 ) yield ()
41
- barrier2.await()
42
- if ((yieldMask and 2 ) != 0 ) yield ()
43
- }
44
- }
45
- oldRunBlockings.addLast(blocking)
46
- val task = async(dispatcher) {
47
- if ((yieldMask and 4 ) != 0 ) yield ()
48
- 42 .also {
49
- if ((yieldMask and 8 ) != 0 ) yield ()
50
- }
51
- }
52
- barrier.await()
53
- task.join()
54
- barrier2.complete(Unit )
55
-
56
- oldRunBlockings.removeIf(Job ::isCompleted)
57
- while (oldRunBlockings.size > 5 ) {
58
- busyWaits++
59
- oldRunBlockings.removeIf(Job ::isCompleted)
60
- }
61
- if (oldRunBlockings.size > maxOldRunBlockings) {
62
- maxOldRunBlockings = oldRunBlockings.size
63
- }
64
- }
65
- }
23
+ fun testLivenessOfDefaultDispatcher (): Unit = testSchedulerLiveness(dispatcher, yieldMask)
66
24
}
0 commit comments