HTTP/2 Allow more time for EventLoopGroup to shutdown in test that use LocalChannel

Motivation:
The CI servers have reported leaks while building the HTTP/2 unit tests. The unit tests attempt to wait for the channels to be closed before exiting the test, but we should wait in case there are any tasks pending on the EventLoopGroup's task queues.

Modifications:
- Change the Future.sync() operations to Future.syncUninterruptibly()
- HTTP/2 unit tests which use local channel should wait for 5 seconds before shutting down the EventLoopGroups

Result:
More likely that any cleanup related tasks will execute before the unit tests are shutdown.
This commit is contained in:
Scott Mitchell 2017-04-06 17:53:04 -07:00
parent c37267d682
commit 1bc5bc69e3
4 changed files with 33 additions and 33 deletions

View File

@ -36,9 +36,9 @@ import org.junit.BeforeClass;
import org.junit.Test;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import static io.netty.handler.codec.http2.Http2CodecUtil.isStreamIdValid;
import static java.util.concurrent.TimeUnit.SECONDS;
import static junit.framework.TestCase.assertFalse;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@ -83,27 +83,27 @@ public class Http2CodecTest {
.group(group)
.handler(new Http2Codec(false, new TestChannelInitializer()));
clientChannel = cb.connect(serverAddress).sync().channel();
assertTrue(serverChannelLatch.await(5, TimeUnit.SECONDS));
assertTrue(serverChannelLatch.await(5, SECONDS));
}
@AfterClass
public static void shutdown() {
group.shutdownGracefully();
group.shutdownGracefully(0, 5, SECONDS);
}
@After
public void tearDown() throws Exception {
if (clientChannel != null) {
clientChannel.close().sync();
clientChannel.close().syncUninterruptibly();
clientChannel = null;
}
if (serverChannel != null) {
serverChannel.close().sync();
serverChannel.close().syncUninterruptibly();
serverChannel = null;
}
final Channel serverConnectedChannel = this.serverConnectedChannel;
if (serverConnectedChannel != null) {
serverConnectedChannel.close().sync();
serverConnectedChannel.close().syncUninterruptibly();
this.serverConnectedChannel = null;
}
}

View File

@ -111,24 +111,24 @@ public class Http2ConnectionRoundtripTest {
@After
public void teardown() throws Exception {
if (clientChannel != null) {
clientChannel.close().sync();
clientChannel.close().syncUninterruptibly();
clientChannel = null;
}
if (serverChannel != null) {
serverChannel.close().sync();
serverChannel.close().syncUninterruptibly();
serverChannel = null;
}
final Channel serverConnectedChannel = this.serverConnectedChannel;
if (serverConnectedChannel != null) {
serverConnectedChannel.close().sync();
serverConnectedChannel.close().syncUninterruptibly();
this.serverConnectedChannel = null;
}
Future<?> serverGroup = sb.config().group().shutdownGracefully(0, 0, MILLISECONDS);
Future<?> serverChildGroup = sb.config().childGroup().shutdownGracefully(0, 0, MILLISECONDS);
Future<?> clientGroup = cb.config().group().shutdownGracefully(0, 0, MILLISECONDS);
serverGroup.sync();
serverChildGroup.sync();
clientGroup.sync();
Future<?> serverGroup = sb.config().group().shutdownGracefully(0, 5, SECONDS);
Future<?> serverChildGroup = sb.config().childGroup().shutdownGracefully(0, 5, SECONDS);
Future<?> clientGroup = cb.config().group().shutdownGracefully(0, 5, SECONDS);
serverGroup.syncUninterruptibly();
serverChildGroup.syncUninterruptibly();
clientGroup.syncUninterruptibly();
}
@Test

View File

@ -105,24 +105,24 @@ public class HttpToHttp2ConnectionHandlerTest {
@After
public void teardown() throws Exception {
if (clientChannel != null) {
clientChannel.close().sync();
clientChannel.close().syncUninterruptibly();
clientChannel = null;
}
if (serverChannel != null) {
serverChannel.close().sync();
serverChannel.close().syncUninterruptibly();
serverChannel = null;
}
final Channel serverConnectedChannel = this.serverConnectedChannel;
if (serverConnectedChannel != null) {
serverConnectedChannel.close().sync();
serverConnectedChannel.close().syncUninterruptibly();
this.serverConnectedChannel = null;
}
Future<?> serverGroup = sb.config().group().shutdownGracefully(0, 0, MILLISECONDS);
Future<?> serverChildGroup = sb.config().childGroup().shutdownGracefully(0, 0, MILLISECONDS);
Future<?> clientGroup = cb.config().group().shutdownGracefully(0, 0, MILLISECONDS);
serverGroup.sync();
serverChildGroup.sync();
clientGroup.sync();
Future<?> serverGroup = sb.config().group().shutdownGracefully(0, 5, SECONDS);
Future<?> serverChildGroup = sb.config().childGroup().shutdownGracefully(0, 5, SECONDS);
Future<?> clientGroup = cb.config().group().shutdownGracefully(0, 5, SECONDS);
serverGroup.syncUninterruptibly();
serverChildGroup.syncUninterruptibly();
clientGroup.syncUninterruptibly();
}
@Test

View File

@ -112,24 +112,24 @@ public class InboundHttp2ToHttpAdapterTest {
cleanupCapturedRequests();
cleanupCapturedResponses();
if (clientChannel != null) {
clientChannel.close().sync();
clientChannel.close().syncUninterruptibly();
clientChannel = null;
}
if (serverChannel != null) {
serverChannel.close().sync();
serverChannel.close().syncUninterruptibly();
serverChannel = null;
}
final Channel serverConnectedChannel = this.serverConnectedChannel;
if (serverConnectedChannel != null) {
serverConnectedChannel.close().sync();
serverConnectedChannel.close().syncUninterruptibly();
this.serverConnectedChannel = null;
}
Future<?> serverGroup = sb.config().group().shutdownGracefully(0, 0, MILLISECONDS);
Future<?> serverChildGroup = sb.config().childGroup().shutdownGracefully(0, 0, MILLISECONDS);
Future<?> clientGroup = cb.config().group().shutdownGracefully(0, 0, MILLISECONDS);
serverGroup.sync();
serverChildGroup.sync();
clientGroup.sync();
Future<?> serverGroup = sb.config().group().shutdownGracefully(0, 5, SECONDS);
Future<?> serverChildGroup = sb.config().childGroup().shutdownGracefully(0, 5, SECONDS);
Future<?> clientGroup = cb.config().group().shutdownGracefully(0, 5, SECONDS);
serverGroup.syncUninterruptibly();
serverChildGroup.syncUninterruptibly();
clientGroup.syncUninterruptibly();
}
@Test