From b3a6f1a32967d2f3a8dea1b2ab9bdfc3757b1d0e Mon Sep 17 00:00:00 2001 From: peter Date: Wed, 22 Feb 2017 14:51:32 +0100 Subject: [PATCH] pump swing events during AsyncHighlighterUpdater.completeAsyncTasks to allow the future to complete at all (IDEA-CR-18495) --- .../impl/text/AsyncHighlighterUpdater.java | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/text/AsyncHighlighterUpdater.java b/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/text/AsyncHighlighterUpdater.java index 7a64fb789dd9..a5a8a5f1c68c 100644 --- a/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/text/AsyncHighlighterUpdater.java +++ b/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/text/AsyncHighlighterUpdater.java @@ -33,9 +33,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.TestOnly; import java.util.Set; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Future; +import java.util.concurrent.*; /** * @author peter @@ -82,15 +80,25 @@ public class AsyncHighlighterUpdater extends ReadTask { @TestOnly public static void completeAsyncTasks() { assert !ApplicationManager.getApplication().isWriteAccessAllowed(); + ApplicationManager.getApplication().invokeAndWait(() -> ourHighlighterFutures.forEach(AsyncHighlighterUpdater::waitForFuture)); UIUtil.dispatchAllInvocationEvents(); - for (Future future : ourHighlighterFutures) { + } + + @TestOnly + private static void waitForFuture(Future future) { + int iteration = 0; + while (!future.isDone() && iteration++ < 1000) { + UIUtil.dispatchAllInvocationEvents(); try { - future.get(); + future.get(10, TimeUnit.MILLISECONDS); + return; + } + catch (TimeoutException ignore) { } catch (Exception e) { throw new RuntimeException(e); } } - UIUtil.dispatchAllInvocationEvents(); + assert future.isDone() : "Too long async highlighter"; } }