From c6bf99c0106c2327d1e83fc4002c06ac7cb6973e Mon Sep 17 00:00:00 2001 From: Mikhail Pyltsin Date: Mon, 20 Jan 2025 19:01:48 +0100 Subject: [PATCH] [java-tests] IDEA-365965 Stopping testNG tests running in parallel doesn't stop the timer and animation on all the running tests GitOrigin-RevId: 8fd17e4f3729aa8eb3135bc33e27728d41d94add --- .../testframework/sm/runner/SMTestProxy.java | 25 ++++++++------ .../sm/runner/SMTestProxyTest.java | 33 +++++++++++++++++++ 2 files changed, 48 insertions(+), 10 deletions(-) diff --git a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/SMTestProxy.java b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/SMTestProxy.java index b305f3d833e8..787796ad1e23 100644 --- a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/SMTestProxy.java +++ b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/SMTestProxy.java @@ -880,24 +880,29 @@ public class SMTestProxy extends AbstractTestProxy implements Navigatable { * @see SMTestProxy#setTerminated */ private void setTerminated(long endTime) { - if (myState.isFinal()) { - return; - } + //some framework can mark suite as passed even if they contain running items, + //so let's check everything but update only running items + boolean beforeIsFinal = myState.isFinal(); if (myEndTime == null) { myEndTime = endTime; } - myState = TerminatedState.INSTANCE; - Long startTime = myStartTime; - if (!myIsSuite && startTime != null) { - setDuration(endTime - startTime); - } else if (!myIsSuite) { - setDuration(0); + if (!beforeIsFinal) { + myState = TerminatedState.INSTANCE; + Long startTime = myStartTime; + if (!myIsSuite && startTime != null) { + setDuration(endTime - startTime); + } + else if (!myIsSuite) { + setDuration(0); + } } final List children = getChildren(); for (SMTestProxy child : children) { child.setTerminated(endTime); } - fireOnNewPrintable(myState); + if (!beforeIsFinal) { + fireOnNewPrintable(myState); + } } /** diff --git a/platform/smRunner/testSrc/com/intellij/execution/testframework/sm/runner/SMTestProxyTest.java b/platform/smRunner/testSrc/com/intellij/execution/testframework/sm/runner/SMTestProxyTest.java index c38f307d4e9c..0f84419e186a 100644 --- a/platform/smRunner/testSrc/com/intellij/execution/testframework/sm/runner/SMTestProxyTest.java +++ b/platform/smRunner/testSrc/com/intellij/execution/testframework/sm/runner/SMTestProxyTest.java @@ -1170,6 +1170,39 @@ public class SMTestProxyTest extends BaseSMTRunnerTestCase { assertNotNull(child2.getEndTimeMillis()); } + public void testTerminatedWithNonFinished() { + SMTestProxy root = createSuiteProxy("root"); + SMTestProxy suite1 = createSuiteProxy("suite1", root); + SMTestProxy suite2 = createSuiteProxy("suite2", root); + + root.setStarted(); + + suite1.setStarted(); + suite1.setFinished(); + + SMTestProxy test1 = createTestProxy("test1", suite1); + SMTestProxy test2 = createTestProxy("test2", suite2); + + test1.setStarted(); + suite2.setStarted(); + test2.setStarted(); + + root.setTerminated(); + + assertNotNull(root.getEndTimeMillis()); + assertNotNull(suite1.getEndTimeMillis()); + assertNotNull(suite2.getEndTimeMillis()); + assertNotNull(test1.getEndTimeMillis()); + assertNotNull(test2.getEndTimeMillis()); + + assertTrue(root.wasTerminated()); + assertTrue(suite1.isPassed()); + assertTrue(suite2.wasTerminated()); + assertTrue(test1.wasTerminated()); + assertTrue(test2.wasTerminated()); + } + + private static void assertDisplayTimeEqualsToSumOfChildren(@NotNull SMTestProxy node) { List children = node.collectChildren(new Filter<>() { @Override