Copilot commented on code in PR #7283:
URL: https://github.com/apache/incubator-kie/pull/7283#discussion_r4536034111


##########
kie-test-util/src/main/java/org/kie/test/util/TestStatusListener.java:
##########
@@ -25,17 +25,22 @@
 import java.lang.management.ThreadMXBean;
 import java.nio.file.Files;
 import java.nio.file.Paths;
+import java.util.Optional;
+import java.util.concurrent.TimeoutException;
 import java.util.stream.Stream;
 
-import org.junit.runner.Description;
-import org.junit.runner.Result;
-import org.junit.runner.notification.Failure;
-import org.junit.runner.notification.RunListener;
-import org.junit.runners.model.TestTimedOutException;
+import org.junit.platform.engine.TestExecutionResult;
+import org.junit.platform.launcher.TestExecutionListener;
+import org.junit.platform.launcher.TestIdentifier;
+import org.junit.platform.launcher.TestPlan;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class TestStatusListener extends RunListener {
+/**
+ * Optional Surefire/JUnit Platform listener that records test lifecycle events
+ * to {@code target/testStatusListener.*.log}. Enable with {@code 
-DenableTestStatusListener}.
+ */
+public class TestStatusListener implements TestExecutionListener {

Review Comment:
   The existing `-DenableTestStatusListener` profile in 
`drools-compiler/pom.xml:227–242` still registers this class through Surefire's 
JUnit 4 `listener` property. A JUnit Platform `TestExecutionListener` is not 
loaded through that property, and there is no corresponding service 
registration, so enabling the profile no longer records lifecycle events or 
timeout thread dumps. Please migrate the registration to the JUnit Platform 
listener mechanism as well, preserving the opt-in behavior.



##########
kie-test-util/src/main/java/org/kie/test/util/TestStatusListener.java:
##########
@@ -114,47 +113,71 @@ private static String fullStackTrace(final ThreadInfo ti) 
{
         return sb.toString();
     }
 
-    @Override
-    public void testRunStarted(final Description description) throws Exception 
{
-        write("testRunStarted", description);
+    private static boolean isTimeoutFailure(final Throwable throwable) {
+        for (Throwable current = throwable; current != null; current = 
current.getCause()) {
+            if (current instanceof TimeoutException
+                    || current.getClass().getSimpleName().contains("Timeout")) 
{
+                return true;
+            }
+            final String message = current.getMessage();
+            if (message != null && message.toLowerCase().contains("timed 
out")) {
+                return true;
+            }
+        }
+        return false;
     }
 
     @Override
-    public void testRunFinished(final Result result) throws Exception {
-        write("testRunFinished", result);
+    public void testPlanExecutionStarted(final TestPlan testPlan) {
+        try {
+            write("testPlanExecutionStarted", "tests=" + 
testPlan.countTestIdentifiers(TestIdentifier::isTest));
+        } catch (final IOException e) {
+            LOG.error("Exception", e);
+        }
     }
 
     @Override
-    public void testStarted(final Description description) throws Exception {
-        write("testStarted", description);
+    public void testPlanExecutionFinished(final TestPlan testPlan) {
+        try {
+            write("testPlanExecutionFinished", "tests=" + 
testPlan.countTestIdentifiers(TestIdentifier::isTest));
+        } catch (final IOException e) {
+            LOG.error("Exception", e);
+        }
     }
 
     @Override
-    public void testFinished(final Description description) throws Exception {
-        write("testFinished", description);
+    public void executionStarted(final TestIdentifier testIdentifier) {
+        try {
+            write("executionStarted", testIdentifier);
+        } catch (final IOException e) {
+            LOG.error("Exception", e);
+        }
     }
 
     @Override
-    public void testFailure(final Failure failure) throws Exception {
-        if ( failure.getException() instanceof TestTimedOutException ) {
-            writeThreadDump();
+    public void executionFinished(final TestIdentifier testIdentifier, final 
TestExecutionResult testExecutionResult) {
+        try {
+            if (testExecutionResult.getStatus() == 
TestExecutionResult.Status.FAILED) {
+                final Optional<Throwable> throwable = 
testExecutionResult.getThrowable();
+                if (throwable.isPresent() && 
isTimeoutFailure(throwable.get())) {
+                    writeThreadDump();
+                }
+                write("executionFailed", testIdentifier.getDisplayName() + 
"\t" + throwable.map(Throwable::toString).orElse(""));
+            } else {
+                write("executionFinished", testIdentifier);

Review Comment:
   JUnit Platform reports failed assumptions as `ABORTED`, so this branch now 
logs them identically to successful tests and discards their reason. The 
previous `testAssumptionFailure` callback recorded that distinction and 
message. Please handle `ABORTED` separately so the status log still identifies 
assumption-aborted tests.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to