/
CoroutinesBlockHoundIntegration.kt
38 lines (33 loc) · 1.8 KB
/
CoroutinesBlockHoundIntegration.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
37
38
@file:Suppress("INVISIBLE_REFERENCE", "INVISIBLE_MEMBER")
package kotlinx.coroutines.debug
import kotlinx.coroutines.scheduling.*
import reactor.blockhound.*
import reactor.blockhound.integration.*
@Suppress("UNUSED")
public class CoroutinesBlockHoundIntegration : BlockHoundIntegration {
override fun applyTo(builder: BlockHound.Builder): Unit = with(builder) {
allowBlockingCallsInside("kotlinx.coroutines.channels.AbstractSendChannel", "sendSuspend")
// these classes use a lock internally
for (method in listOf(
"pollInternal", "isEmpty", "isFull", "isClosedForReceive", "offerInternal", "offerSelectInternal",
"enqueueSend", "pollInternal", "pollSelectInternal", "enqueueReceiveInternal", "onCancelIdempotent" ))
{
allowBlockingCallsInside("kotlinx.coroutines.channels.ArrayChannel", method)
}
for (method in listOf("offerInternal", "offerSelectInternal", "updateHead")) {
allowBlockingCallsInside("kotlinx.coroutines.channels.ArrayBroadcastChannel", method)
}
for (method in listOf("checkOffer", "pollInternal", "pollSelectInternal")) {
allowBlockingCallsInside("kotlinx.coroutines.channels.ArrayBroadcastChannel\$Subscriber", method)
}
for (method in listOf("offerInternal", "offerSelectInternal", "pollInternal", "pollSelectInternal",
"onCancelIdempotent"))
{
allowBlockingCallsInside("kotlinx.coroutines.channels.ConflatedChannel", method)
}
// should be safe; used for sending tasks to a thread pool
allowBlockingCallsInside("java.util.concurrent.ScheduledThreadPoolExecutor", "execute")
addDynamicThreadPredicate { isSchedulerWorker(it) }
nonBlockingThreadPredicate { p -> p.or { mayNotBlock(it) } }
}
}