NonBlockingReadActionImpl.waitForAsyncTaskCompletion: don't hang forever in dumb mode in tests

GitOrigin-RevId: 9381545ea8199d1da001e26d1686569b19a4bd9a
This commit is contained in:
Peter Gromov
2020-09-02 16:19:07 +00:00
committed by intellij-monorepo-bot
parent e819c24c6b
commit 330669bb22
@@ -594,6 +594,11 @@ public class NonBlockingReadActionImpl<T> implements NonBlockingReadAction<T> {
return ContainerUtil.find(myConstraints, t -> !t.isCorrectContext());
}
/**
* Waits and pumps UI events until all submitted non-blocking read actions have completed. But only if they have chance to:
* in dumb mode, submissions with {@link #inSmartMode} are ignored, because dumbness works differently in tests,
* and a test might never switch to the smart mode at all.
*/
@TestOnly
public static void waitForAsyncTaskCompletion() {
assert !ApplicationManager.getApplication().isWriteAccessAllowed();
@@ -604,6 +609,12 @@ public class NonBlockingReadActionImpl<T> implements NonBlockingReadAction<T> {
@TestOnly
private static void waitForTask(@NotNull Submission<?> task) {
for (ContextConstraint constraint : task.builder.myConstraints) {
if (constraint instanceof InSmartMode && !constraint.isCorrectContext()) {
return;
}
}
int iteration = 0;
while (!task.isDone() && iteration++ < 60_000) {
UIUtil.dispatchAllInvocationEvents();