From c195b7821e88fc81563fc7935100897b328ebfd3 Mon Sep 17 00:00:00 2001 From: "Gregory.Shrago" Date: Tue, 10 Oct 2017 18:34:23 +0300 Subject: [PATCH] waitForPromise: return promise result if present --- .../src/com/intellij/testFramework/PlatformTestUtil.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/platform/testFramework/src/com/intellij/testFramework/PlatformTestUtil.java b/platform/testFramework/src/com/intellij/testFramework/PlatformTestUtil.java index 4f46000c2ed0..23b1ac45c497 100644 --- a/platform/testFramework/src/com/intellij/testFramework/PlatformTestUtil.java +++ b/platform/testFramework/src/com/intellij/testFramework/PlatformTestUtil.java @@ -249,17 +249,19 @@ public class PlatformTestUtil { } @TestOnly - public static void waitForPromise(@NotNull Promise promise) { + @Nullable + public static T waitForPromise(@NotNull Promise promise) { Application app = ApplicationManager.getApplication(); assert !app.isWriteAccessAllowed() : "It's a bad idea to wait for a promise under the write action. Somebody creates an alarm which requires read action and you are deadlocked."; assert app.isDispatchThread(); AtomicBoolean complete = new AtomicBoolean(false); promise.processed(ignore -> complete.set(true)); + T result = null; long start = System.currentTimeMillis(); while (!complete.get()) { UIUtil.dispatchAllInvocationEvents(); try { - promise.blockingGet(20, TimeUnit.MILLISECONDS); + result = promise.blockingGet(20, TimeUnit.MILLISECONDS); } catch (Exception ignore) { } @@ -268,6 +270,7 @@ public class PlatformTestUtil { } } UIUtil.dispatchAllInvocationEvents(); + return result; } @TestOnly