When BlockHound is installed, do not report GlobalEventExecutor/SingleThreadEventExecutor#takeTask as blocking call. (#10020)
Motivation: GlobalEventExecutor/SingleThreadEventExecutor#taskQueue is BlockingQueue. Modifications: Add allowBlockingCallsInside configuration for GlobalEventExecutor/SingleThreadEventExecutor#takeTask. Result: Fixes #9984 When BlockHound is installed, GlobalEventExecutor/SingleThreadEventExecutor#takeTask is not reported as a blocking call.
This commit is contained in:
parent
2d4b5abc99
commit
fcf55fcf71
@ -75,6 +75,14 @@ class Hidden {
|
||||
"runAllDelegatedTasks"
|
||||
);
|
||||
|
||||
builder.allowBlockingCallsInside(
|
||||
"io.netty.util.concurrent.GlobalEventExecutor",
|
||||
"takeTask");
|
||||
|
||||
builder.allowBlockingCallsInside(
|
||||
"io.netty.util.concurrent.SingleThreadEventExecutor",
|
||||
"takeTask");
|
||||
|
||||
builder.nonBlockingThreadPredicate(new Function<Predicate<Thread>, Predicate<Thread>>() {
|
||||
@Override
|
||||
public Predicate<Thread> apply(final Predicate<Thread> p) {
|
||||
|
@ -35,9 +35,13 @@ import io.netty.handler.ssl.SslProvider;
|
||||
import io.netty.handler.ssl.util.InsecureTrustManagerFactory;
|
||||
import io.netty.handler.ssl.util.SelfSignedCertificate;
|
||||
import io.netty.util.ReferenceCountUtil;
|
||||
import io.netty.util.concurrent.DefaultThreadFactory;
|
||||
import io.netty.util.concurrent.EventExecutor;
|
||||
import io.netty.util.concurrent.GlobalEventExecutor;
|
||||
import io.netty.util.concurrent.ImmediateEventExecutor;
|
||||
import io.netty.util.concurrent.ImmediateExecutor;
|
||||
import io.netty.util.concurrent.ScheduledFuture;
|
||||
import io.netty.util.concurrent.SingleThreadEventExecutor;
|
||||
import io.netty.util.internal.Hidden.NettyBlockHoundIntegration;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.BeforeClass;
|
||||
@ -48,6 +52,7 @@ import reactor.blockhound.integration.BlockHoundIntegration;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.ServiceLoader;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
@ -94,6 +99,35 @@ public class NettyBlockHoundIntegrationTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test(timeout = 5000L)
|
||||
public void testGlobalEventExecutorTakeTask() throws InterruptedException {
|
||||
testEventExecutorTakeTask(GlobalEventExecutor.INSTANCE);
|
||||
}
|
||||
|
||||
@Test(timeout = 5000L)
|
||||
public void testSingleThreadEventExecutorTakeTask() throws InterruptedException {
|
||||
SingleThreadEventExecutor executor =
|
||||
new SingleThreadEventExecutor(null, new DefaultThreadFactory("test"), true) {
|
||||
@Override
|
||||
protected void run() {
|
||||
while (!confirmShutdown()) {
|
||||
Runnable task = takeTask();
|
||||
if (task != null) {
|
||||
task.run();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
testEventExecutorTakeTask(executor);
|
||||
}
|
||||
|
||||
private static void testEventExecutorTakeTask(EventExecutor eventExecutor) throws InterruptedException {
|
||||
CountDownLatch latch = new CountDownLatch(1);
|
||||
ScheduledFuture<?> f = eventExecutor.schedule(latch::countDown, 10, TimeUnit.MILLISECONDS);
|
||||
f.sync();
|
||||
latch.await();
|
||||
}
|
||||
|
||||
// Tests copied from io.netty.handler.ssl.SslHandlerTest
|
||||
@Test
|
||||
public void testHandshakeWithExecutorThatExecuteDirectory() throws Exception {
|
||||
|
Loading…
Reference in New Issue
Block a user