chia7712 commented on code in PR #16499: URL: https://github.com/apache/kafka/pull/16499#discussion_r1686179974
########## 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: " + Review Comment: We need to display the threads from "last" call rather than the "initial" call. ```java AtomicReference<List<Thread>> lastThread = new AtomicReference<>(); TestUtils.waitForCondition(() -> { List<Thread> threads = detectThreadLeak.newThreads(); lastThread.set(threads); return threads.isEmpty(); }, () -> "Thread leak detected: " + lastThread.get().stream().map(Thread::getName).collect(Collectors.joining(", "))); ``` -- 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