Skip to content

Commit

Permalink
Fix event loop thread leak
Browse files Browse the repository at this point in the history
  • Loading branch information
lhotari committed Oct 28, 2023
1 parent b442d64 commit 6c35438
Showing 1 changed file with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@
import io.netty.buffer.Unpooled;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.DefaultEventLoop;
import io.netty.channel.DefaultEventLoopGroup;
import io.netty.channel.EventLoopGroup;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.net.InetAddress;
Expand Down Expand Up @@ -164,6 +165,7 @@ public class PersistentTopicTest extends MockedBookKeeperTestCase {

private BrokerService brokerService;

private EventLoopGroup eventLoopGroup;

@BeforeMethod(alwaysRun = true)
public void setup() throws Exception {
Expand Down Expand Up @@ -202,7 +204,9 @@ public void setup() throws Exception {
.when(serverCnx).getCommandSender();
ChannelHandlerContext ctx = mock(ChannelHandlerContext.class);
Channel channel = mock(Channel.class);
doReturn(spy(DefaultEventLoop.class)).when(channel).eventLoop();

eventLoopGroup = new DefaultEventLoopGroup();
doReturn(eventLoopGroup.next()).when(channel).eventLoop();
doReturn(channel).when(ctx).channel();
doReturn(ctx).when(serverCnx).ctx();

Expand All @@ -224,6 +228,10 @@ public void teardown() throws Exception {
pulsarTestContext.close();
pulsarTestContext = null;
}
if (eventLoopGroup != null) {
eventLoopGroup.shutdownNow();
eventLoopGroup = null;
}
}

@Test
Expand Down

0 comments on commit 6c35438

Please sign in to comment.