From 71c4b8b93ff7eb753eca6783452f50801f5dfaa1 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Thu, 3 Dec 2015 15:13:33 +0300 Subject: [PATCH] wait for dumb mode in tests (unless explicitly told to not to via DaemonCodeAnalyzerImpl.mustWaitForSmartMode(false)). This way there should be fewer blinking tests due to unexpected daemon restarts. --- .../daemon/impl/DaemonCodeAnalyzerImpl.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DaemonCodeAnalyzerImpl.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DaemonCodeAnalyzerImpl.java index f49f224754b8..18033bd819eb 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DaemonCodeAnalyzerImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DaemonCodeAnalyzerImpl.java @@ -58,6 +58,7 @@ import com.intellij.openapi.fileTypes.impl.FileTypeManagerImpl; import com.intellij.openapi.progress.ProcessCanceledException; import com.intellij.openapi.progress.ProgressIndicator; import com.intellij.openapi.progress.ProgressManager; +import com.intellij.openapi.project.DumbService; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.Key; @@ -307,6 +308,19 @@ public class DaemonCodeAnalyzerImpl extends DaemonCodeAnalyzerEx implements Pers return runPasses(file, document, Collections.singletonList(textEditor), toIgnore, canChangeDocument, callbackWhileWaiting); } + private volatile boolean mustWaitForSmartMode = true; + @TestOnly + public void mustWaitForSmartMode(final boolean mustWait, @NotNull Disposable parent) { + final boolean old = mustWaitForSmartMode; + mustWaitForSmartMode = mustWait; + Disposer.register(parent, new Disposable() { + @Override + public void dispose() { + mustWaitForSmartMode = old; + } + }); + } + @NotNull @TestOnly List runPasses(@NotNull PsiFile file, @@ -331,6 +345,13 @@ public class DaemonCodeAnalyzerImpl extends DaemonCodeAnalyzerEx implements Pers while (RefreshQueueImpl.isRefreshInProgress() || HeavyProcessLatch.INSTANCE.isRunning()) { UIUtil.dispatchAllInvocationEvents(); } + long dstart = System.currentTimeMillis(); + while (mustWaitForSmartMode && DumbService.getInstance(myProject).isDumb()) { + if (System.currentTimeMillis() > dstart + 100000) { + throw new IllegalStateException("Timeout waiting for smart mode. If you absolutely want to be dumb, please use DaemonCodeAnalyzerImpl.mustWaitForSmartMode(false)."); + } + UIUtil.dispatchAllInvocationEvents(); + } UIUtil.dispatchAllInvocationEvents();