IDEA-191597 IndexNotReadyInspection on save test history

This commit is contained in:
Dmitry Avdeev
2018-05-15 16:59:51 +03:00
parent 97c15b63a4
commit d2434e0b5e
2 changed files with 51 additions and 15 deletions
@@ -3,23 +3,34 @@ package com.intellij.java.codeInsight.navigation;
import com.intellij.codeInsight.daemon.impl.HighlightInfo;
import com.intellij.execution.TestStateStorage;
import com.intellij.execution.executors.DefaultDebugExecutor;
import com.intellij.execution.testframework.JavaTestLocator;
import com.intellij.execution.testframework.TestConsoleProperties;
import com.intellij.execution.testframework.TestFailedLineInspection;
import com.intellij.execution.testframework.sm.runner.MockRuntimeConfiguration;
import com.intellij.execution.testframework.sm.runner.SMTRunnerConsoleProperties;
import com.intellij.execution.testframework.sm.runner.SMTestProxy;
import com.intellij.execution.testframework.sm.runner.states.TestStateInfo;
import com.intellij.execution.testframework.sm.runner.ui.SMTRunnerConsoleView;
import com.intellij.execution.testframework.sm.runner.ui.SMTestRunnerResultsForm;
import com.intellij.execution.testframework.sm.runner.ui.TestStackTraceParser;
import com.intellij.lang.annotation.HighlightSeverity;
import com.intellij.openapi.editor.markup.EffectType;
import com.intellij.openapi.editor.markup.TextAttributes;
import com.intellij.openapi.project.DumbServiceImpl;
import com.intellij.openapi.util.Disposer;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiMethod;
import com.intellij.psi.PsiMethodCallExpression;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.psi.util.PsiUtilBase;
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;
import com.intellij.execution.testframework.TestFailedLineInspection;
import com.intellij.testIntegration.TestFailedLineManager;
import org.jetbrains.ide.PooledThreadExecutor;
import java.util.Date;
import java.util.List;
import java.util.concurrent.TimeUnit;
public class FailedLineTest extends LightCodeInsightFixtureTestCase {
@@ -52,6 +63,30 @@ public class FailedLineTest extends LightCodeInsightFixtureTestCase {
assertEquals("\tat MainTest.assertEquals(Assert.java:207)", record.topStacktraceLine);
}
public void testDumbMode() throws InterruptedException {
TestConsoleProperties consoleProperties = new SMTRunnerConsoleProperties(new MockRuntimeConfiguration(getProject()), "SMRunnerTests",
DefaultDebugExecutor.getDebugExecutorInstance());
SMTRunnerConsoleView view = new SMTRunnerConsoleView(consoleProperties);
try {
DumbServiceImpl.getInstance(getProject()).setDumb(true);
String url = "schema://url";
SMTestProxy test = new SMTestProxy("foo", false, url);
test.setLocator(JavaTestLocator.INSTANCE);
view.initUI();
SMTestRunnerResultsForm form = view.getResultsViewer();
form.getTestsRootNode().addChild(test);
test.setTestFailed("oops", "stacktrace", true);
form.onTestingFinished(form.getTestsRootNode());
PooledThreadExecutor.INSTANCE.awaitTermination(1, TimeUnit.SECONDS);
}
finally {
Disposer.dispose(view);
DumbServiceImpl.getInstance(getProject()).setDumb(false);
}
}
private TestStateStorage.Record configure() {
myFixture.addClass("package junit.framework; public class TestCase {}");
myFixture.configureByText("MainTest.java", " public class MainTest extends junit.framework.TestCase {\n" +
@@ -48,6 +48,7 @@ import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.progress.Task;
import com.intellij.openapi.progress.impl.BackgroundableProcessIndicator;
import com.intellij.openapi.progress.util.ColorProgressBar;
import com.intellij.openapi.project.DumbService;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.Disposer;
@@ -340,7 +341,6 @@ public class SMTestRunnerResultsForm extends TestResultsPanel
final RunProfile configuration = consoleProperties.getConfiguration();
if (configuration instanceof RunConfiguration &&
!(consoleProperties instanceof ImportedTestConsoleProperties) &&
!ApplicationManager.getApplication().isUnitTestMode() &&
!myDisposed) {
final MySaveHistoryTask backgroundable = new MySaveHistoryTask(consoleProperties, root, (RunConfiguration)configuration);
final BackgroundableProcessIndicator processIndicator = new BackgroundableProcessIndicator(backgroundable);
@@ -832,24 +832,25 @@ public class SMTestRunnerResultsForm extends TestResultsPanel
}
private void writeState() {
// read action to prevent project (and storage) from being disposed
ApplicationManager.getApplication().runReadAction(() -> {
Project project = getProject();
if (project.isDisposed() || myRoot == null) return;
TestStateStorage storage = TestStateStorage.getInstance(project);
List<SMTestProxy> tests = myRoot.getAllTests();
for (SMTestProxy proxy : tests) {
String url = proxy instanceof SMTestProxy.SMRootTestProxy ? ((SMTestProxy.SMRootTestProxy)proxy).getRootLocation() : proxy.getLocationUrl();
if (url != null) {
String configurationName = myConfiguration != null ? myConfiguration.getName() : null;
TestStackTraceParser info = new TestStackTraceParser(url, proxy.getStacktrace(), proxy.getErrorMessage(), proxy.getLocator(), project);
if (myRoot == null) return;
List<SMTestProxy> tests = myRoot.getAllTests();
for (SMTestProxy proxy : tests) {
String url =
proxy instanceof SMTestProxy.SMRootTestProxy ? ((SMTestProxy.SMRootTestProxy)proxy).getRootLocation() : proxy.getLocationUrl();
if (url != null) {
String configurationName = myConfiguration != null ? myConfiguration.getName() : null;
DumbService.getInstance(getProject()).runWhenSmart(() -> {
Project project = getProject();
TestStackTraceParser info =
new TestStackTraceParser(url, proxy.getStacktrace(), proxy.getErrorMessage(), proxy.getLocator(), project);
TestStateStorage storage = TestStateStorage.getInstance(project);
storage.writeState(url, new TestStateStorage.Record(proxy.getMagnitude(), new Date(),
configurationName == null ? 0 : configurationName.hashCode(),
info.getFailedLine(), info.getFailedMethodName(),
info.getErrorMessage(), info.getTopLocationLine()));
}
});
}
});
}
}
@Override