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.

This commit is contained in:
Alexey Kudravtsev
2015-12-03 16:51:25 +03:00
parent 562c13f32d
commit 71c4b8b93f
@@ -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<HighlightInfo> 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();