diff --git a/java/execution/impl/src/com/intellij/execution/testframework/SearchForTestsTask.java b/java/execution/impl/src/com/intellij/execution/testframework/SearchForTestsTask.java index 58288410c8bf..536ced5df441 100644 --- a/java/execution/impl/src/com/intellij/execution/testframework/SearchForTestsTask.java +++ b/java/execution/impl/src/com/intellij/execution/testframework/SearchForTestsTask.java @@ -31,6 +31,7 @@ import com.intellij.openapi.progress.impl.BackgroundableProcessIndicator; import com.intellij.openapi.progress.util.ProgressIndicatorUtils; import com.intellij.openapi.project.DumbService; import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.registry.Registry; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -112,8 +113,13 @@ public abstract class SearchForTestsTask extends Task.Backgroundable { ex[0] = e; } }; - //noinspection StatementWithEmptyBody - while (!runSmartModeReadActionWithWritePriority(runnable, new SensitiveProgressWrapper(indicator))); + if (Registry.is("junit4.search.4.tests.in.classpath", false)) { + runnable.run(); + } + else { + //noinspection StatementWithEmptyBody + while (!runSmartModeReadActionWithWritePriority(runnable, new SensitiveProgressWrapper(indicator))); + } if (ex[0] != null) { logCantRunException(ex[0]); } @@ -169,7 +175,7 @@ public abstract class SearchForTestsTask extends Task.Backgroundable { @Override public void onSuccess() { - DumbService.getInstance(getProject()).runWhenSmart(() -> { + Runnable runnable = () -> { try { onFound(); } @@ -177,7 +183,13 @@ public abstract class SearchForTestsTask extends Task.Backgroundable { LOG.error(e); } finish(); - }); + }; + if (Registry.is("junit4.search.4.tests.in.classpath", false)) { + runnable.run(); + } + else { + DumbService.getInstance(getProject()).runWhenSmart(runnable); + } } public void finish() { diff --git a/plugins/junit/src/com/intellij/execution/junit/TestPackage.java b/plugins/junit/src/com/intellij/execution/junit/TestPackage.java index 17e5c5797c75..dbab469fcbdf 100644 --- a/plugins/junit/src/com/intellij/execution/junit/TestPackage.java +++ b/plugins/junit/src/com/intellij/execution/junit/TestPackage.java @@ -26,6 +26,7 @@ import com.intellij.execution.testframework.SourceScope; import com.intellij.execution.testframework.TestSearchScope; import com.intellij.openapi.application.ReadAction; import com.intellij.openapi.module.Module; +import com.intellij.openapi.project.DumbService; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Comparing; import com.intellij.openapi.util.Ref; @@ -71,7 +72,9 @@ public class TestPackage extends TestObject { final SourceScope sourceScope = getSourceScope(); final Module module = getConfiguration().getConfigurationModule().getModule(); if (sourceScope != null && !ReadAction.compute(() -> isJUnit5(module, sourceScope, myProject))) { + DumbService instance = DumbService.getInstance(myProject); try { + instance.setAlternativeResolveEnabled(true); final TestClassFilter classFilter = getClassFilter(data); LOG.assertTrue(classFilter.getBase() != null); long start = System.currentTimeMillis(); @@ -81,7 +84,7 @@ public class TestPackage extends TestObject { PsiManager manager = PsiManager.getInstance(myProject); Arrays.stream(classNames) .filter(className -> acceptClassName(className)) //check patterns - .map(name -> ClassUtil.findPsiClass(manager, name, null, true, classFilter.getScope())) + .map(name -> ReadAction.compute(() -> ClassUtil.findPsiClass(manager, name, null, true, classFilter.getScope()))) .filter(aClass -> aClass != null) .forEach(myClasses::add); LOG.info("Found tests in " + (System.currentTimeMillis() - start)); @@ -91,6 +94,9 @@ public class TestPackage extends TestObject { } } catch (CantRunException ignored) {} + finally { + instance.setAlternativeResolveEnabled(false); + } } }