-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathRunBlockingDispatchLocalTasksTest.kt
36 lines (33 loc) · 1.18 KB
/
RunBlockingDispatchLocalTasksTest.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package kotlinx.coroutines
import java.util.concurrent.*
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
import kotlin.test.*
class RunBlockingDispatchLocalTasksTest {
// A coroutine deadlock occurs if there is a task in the local queue
// of the blocking thread before it is parked by the nested runBlocking
@Test(timeout = 1000)
fun testEmptyLocalTasksBeforePark() {
runBlocking(Dispatchers.IO) {
val latch = CountDownLatch(1)
lateinit var launchContinuation: Continuation<Unit>
lateinit var runBlockingContinuation: Continuation<Unit>
CoroutineScope(Dispatchers.IO).launch {
suspendCoroutineUninterceptedOrReturn {
launchContinuation = it
latch.countDown()
COROUTINE_SUSPENDED
}
yield()
runBlockingContinuation.resume(Unit)
}
latch.await()
runBlocking {
suspendCancellableCoroutine {
runBlockingContinuation = it
launchContinuation.resume(Unit)
}
}
}
}
}