diff --git a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/GeneralToSMTRunnerEventsConvertor.java b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/GeneralToSMTRunnerEventsConvertor.java index 895f0cb8ec41..6acbd868c15b 100644 --- a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/GeneralToSMTRunnerEventsConvertor.java +++ b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/GeneralToSMTRunnerEventsConvertor.java @@ -23,9 +23,7 @@ public class GeneralToSMTRunnerEventsConvertor extends GeneralTestEventsProcesso private final Map myRunningTestsFullNameToProxy = new HashMap<>(); private final TestSuiteStack mySuitesStack; - private final Set myCurrentChildren = new LinkedHashSet<>(); - private boolean myGetChildren = true; - + private final Map> myCurrentChildren = new HashMap<>(); private boolean myIsTestingFinished; @@ -62,6 +60,12 @@ public class GeneralToSMTRunnerEventsConvertor extends GeneralTestEventsProcesso super.onSuiteTreeEnded(suiteName); } + @Override + public void onBuildTreeEnded() { + super.onBuildTreeEnded(); + initCurrentChildren(myTestsRootProxy); + } + @Override public void onStartTesting() { //fire @@ -100,6 +104,7 @@ public class GeneralToSMTRunnerEventsConvertor extends GeneralTestEventsProcesso } mySuitesStack.clear(); myTestsRootProxy.setFinished(); + myCurrentChildren.clear(); //fire events @@ -146,15 +151,6 @@ public class GeneralToSMTRunnerEventsConvertor extends GeneralTestEventsProcesso } parentSuite.addChild(testProxy); - - if (myTreeBuildBeforeStart && myGetChildren) { - for (SMTestProxy proxy : parentSuite.getChildren()) { - if (!proxy.isFinal()) { - myCurrentChildren.add(proxy); - } - } - myGetChildren = false; - } } // adds to running tests map @@ -192,7 +188,7 @@ public class GeneralToSMTRunnerEventsConvertor extends GeneralTestEventsProcesso parentSuite.addChild(newSuite); } - myGetChildren = true; + initCurrentChildren(newSuite); mySuitesStack.pushSuite(newSuite); //Progress started @@ -202,6 +198,20 @@ public class GeneralToSMTRunnerEventsConvertor extends GeneralTestEventsProcesso fireOnSuiteStarted(newSuite); } + private void initCurrentChildren(SMTestProxy newSuite) { + if (myTreeBuildBeforeStart) { + for (SMTestProxy proxy : newSuite.getChildren()) { + if (!proxy.isFinal()) { + String url = proxy.getLocationUrl(); + if (url != null) { + myCurrentChildren.computeIfAbsent(url, l -> new ArrayList<>()).add(proxy); + } + myCurrentChildren.computeIfAbsent(proxy.getName(), l -> new ArrayList<>()).add(proxy); + } + } + } + } + private SMTestProxy findChildByName(SMTestProxy parentSuite, String fullName, boolean preferSuite) { return findChild(parentSuite, fullName, SMTestProxy::getName, preferSuite); } @@ -216,17 +226,19 @@ public class GeneralToSMTRunnerEventsConvertor extends GeneralTestEventsProcesso boolean preferSuite) { if (myTreeBuildBeforeStart) { Set acceptedProxies = new LinkedHashSet<>(); - final Collection children = myGetChildren ? parentSuite.getChildren() : myCurrentChildren; - for (SMTestProxy proxy : children) { - if (fullName.equals(nameFunction.fun(proxy)) && !proxy.isFinal()) { - acceptedProxies.add(proxy); + Collection children = myCurrentChildren.get(fullName); + if (children != null) { //null if child started second time + for (SMTestProxy proxy : children) { + if (fullName.equals(nameFunction.fun(proxy)) && !proxy.isFinal()) { + acceptedProxies.add(proxy); + } + } + if (!acceptedProxies.isEmpty()) { + return acceptedProxies.stream() + .filter(proxy -> proxy.isSuite() == preferSuite) + .findFirst() + .orElse(acceptedProxies.iterator().next()); } - } - if (!acceptedProxies.isEmpty()) { - return acceptedProxies.stream() - .filter(proxy -> proxy.isSuite() == preferSuite) - .findFirst() - .orElse(acceptedProxies.iterator().next()); } } return null; @@ -249,12 +261,20 @@ public class GeneralToSMTRunnerEventsConvertor extends GeneralTestEventsProcesso testProxy.setFrameworkOutputFile(testFinishedEvent.getOutputFile()); testProxy.setFinished(); myRunningTestsFullNameToProxy.remove(fullTestName); - myCurrentChildren.remove(testProxy); + clearCurrentChildren(fullTestName, testProxy); //fire events fireOnTestFinished(testProxy); } + private void clearCurrentChildren(String fullTestName, SMTestProxy testProxy) { + myCurrentChildren.remove(fullTestName); + String url = testProxy.getLocationUrl(); + if (url != null) { + myCurrentChildren.remove(url); + } + } + @Override public void onSuiteFinished(@NotNull final TestSuiteFinishedEvent suiteFinishedEvent) { //fire events @@ -262,8 +282,11 @@ public class GeneralToSMTRunnerEventsConvertor extends GeneralTestEventsProcesso final SMTestProxy mySuite = mySuitesStack.popSuite(suiteName); if (mySuite != null) { mySuite.setFinished(); - myCurrentChildren.clear(); - myGetChildren = true; + myCurrentChildren.remove(suiteName); + String locationUrl = mySuite.getLocationUrl(); + if (locationUrl != null) { + myCurrentChildren.remove(locationUrl); + } //fire events fireOnSuiteFinished(mySuite); @@ -420,7 +443,6 @@ public class GeneralToSMTRunnerEventsConvertor extends GeneralTestEventsProcesso // current suite shouldn't be null otherwise test runner isn't correct // or may be we are in debug mode logProblem("Current suite is undefined. Root suite will be used."); - myGetChildren = true; return myTestsRootProxy; } diff --git a/platform/smRunner/testSrc/com/intellij/execution/testframework/sm/runner/ui/SMTestRunnerResultsFormTest.java b/platform/smRunner/testSrc/com/intellij/execution/testframework/sm/runner/ui/SMTestRunnerResultsFormTest.java index 099e48fff404..b709ac3dde22 100644 --- a/platform/smRunner/testSrc/com/intellij/execution/testframework/sm/runner/ui/SMTestRunnerResultsFormTest.java +++ b/platform/smRunner/testSrc/com/intellij/execution/testframework/sm/runner/ui/SMTestRunnerResultsFormTest.java @@ -264,6 +264,7 @@ public class SMTestRunnerResultsFormTest extends BaseSMTRunnerTestCase { myEventsProcessor.onSuiteTreeStarted("suite1", null, null, "suite1", "0"); myEventsProcessor.onSuiteTreeNodeAdded("test1", null, null,"test1", "suite1"); myEventsProcessor.onSuiteTreeEnded("suite1"); + myEventsProcessor.onBuildTreeEnded(); //start testing myEventsProcessor.onStartTesting();