From 042b32d1a2d21b28ff9ccbb65298e1631beabac7 Mon Sep 17 00:00:00 2001 From: Alexandr Evstigneev Date: Thu, 20 Sep 2018 17:05:51 +0300 Subject: [PATCH] Inroduced waitForPromise with custom timeout --- .../intellij/testFramework/PlatformTestUtil.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/platform/testFramework/src/com/intellij/testFramework/PlatformTestUtil.java b/platform/testFramework/src/com/intellij/testFramework/PlatformTestUtil.java index daf0523fb54f..333ab9130e09 100644 --- a/platform/testFramework/src/com/intellij/testFramework/PlatformTestUtil.java +++ b/platform/testFramework/src/com/intellij/testFramework/PlatformTestUtil.java @@ -78,8 +78,8 @@ import java.io.OutputStream; import java.io.PrintStream; import java.lang.reflect.Method; import java.nio.charset.Charset; -import java.util.*; import java.util.List; +import java.util.*; import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; @@ -264,7 +264,11 @@ public class PlatformTestUtil { } private static void assertMaxWaitTimeSince(long startTimeMillis) { - assert getMillisSince(startTimeMillis) <= MAX_WAIT_TIME : "the waiting takes too long"; + assertMaxWaitTimeSince(startTimeMillis, MAX_WAIT_TIME); + } + + private static void assertMaxWaitTimeSince(long startTimeMillis, long timeout) { + assert getMillisSince(startTimeMillis) <= timeout : "the waiting takes too long"; } private static void assertDispatchThreadWithoutWriteAccess() { @@ -314,6 +318,11 @@ public class PlatformTestUtil { @Nullable public static T waitForPromise(@NotNull Promise promise) { + return waitForPromise(promise, MAX_WAIT_TIME); + } + + @Nullable + public static T waitForPromise(@NotNull Promise promise, long timeout) { assertDispatchThreadWithoutWriteAccess(); AtomicBoolean complete = new AtomicBoolean(false); promise.onProcessed(ignore -> complete.set(true)); @@ -326,7 +335,7 @@ public class PlatformTestUtil { } catch (Exception ignore) { } - assertMaxWaitTimeSince(start); + assertMaxWaitTimeSince(start, timeout); } while (!complete.get()); UIUtil.dispatchAllInvocationEvents();