chia7712 commented on code in PR #16499: URL: https://github.com/apache/kafka/pull/16499#discussion_r1685709868
########## core/src/test/java/kafka/test/junit/ClusterTestExtensions.java: ########## @@ -119,7 +139,27 @@ public Stream<TestTemplateInvocationContext> provideTestTemplateInvocationContex return generatedContexts.stream(); } + @Override + public void beforeEach(ExtensionContext context) { + DetectThreadLeak detectThreadLeak = DetectThreadLeak.of(thread -> + SKIPPED_THREAD_PREFIX.stream().noneMatch(prefix -> thread.getName().startsWith(prefix))); + getStore(context).put(DETECT_THREAD_LEAK_KEY, detectThreadLeak); + } + + @Override + public void afterEach(ExtensionContext context) throws InterruptedException { + DetectThreadLeak detectThreadLeak = getStore(context).remove(DETECT_THREAD_LEAK_KEY, DetectThreadLeak.class); + if (detectThreadLeak == null) { + return; + } + TestUtils.waitForCondition(() -> detectThreadLeak.newThreads().isEmpty(), + "Thread leak detected: " + + detectThreadLeak.newThreads().stream().map(Thread::getName).collect(Collectors.joining(", "))); + } + private Store getStore(ExtensionContext context) { + return context.getStore(Namespace.create(getClass(), context.getUniqueId())); Review Comment: `getClass()` we don't need this as it is always the same for all test cases. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org