From f27e8d2aafd38412d1fb901f73b74ae1830e9edc Mon Sep 17 00:00:00 2001 From: Artem Bukhonov Date: Tue, 10 Apr 2018 16:25:46 +0200 Subject: [PATCH] XDebuggerTestUtil overloads which take custom waiter function as parameter --- .../intellij/xdebugger/XDebuggerTestUtil.java | 101 +++++++++++++++--- .../intellij/xdebugger/XTestContainer.java | 7 +- .../xdebugger/XTestEvaluationCallback.java | 7 +- .../intellij/xdebugger/XTestValueNode.java | 6 +- 4 files changed, 104 insertions(+), 17 deletions(-) diff --git a/platform/xdebugger-impl/testSrc/com/intellij/xdebugger/XDebuggerTestUtil.java b/platform/xdebugger-impl/testSrc/com/intellij/xdebugger/XDebuggerTestUtil.java index db43e9fcbe07..afbddb77ce00 100644 --- a/platform/xdebugger-impl/testSrc/com/intellij/xdebugger/XDebuggerTestUtil.java +++ b/platform/xdebugger-impl/testSrc/com/intellij/xdebugger/XDebuggerTestUtil.java @@ -38,6 +38,7 @@ import java.util.List; import java.util.concurrent.ExecutionException; import java.util.concurrent.Semaphore; import java.util.concurrent.TimeUnit; +import java.util.function.BiFunction; import java.util.concurrent.TimeoutException; import static org.junit.Assert.*; @@ -122,9 +123,13 @@ public class XDebuggerTestUtil { } public static Pair, String> collectThreadsWithErrors(@NotNull XDebugSession session) { + return collectThreadsWithErrors(session, XDebuggerTestUtil::waitFor); + } + + public static Pair, String> collectThreadsWithErrors(@NotNull XDebugSession session, @NotNull BiFunction waitFunction) { XTestExecutionStackContainer container = new XTestExecutionStackContainer(); session.getSuspendContext().computeExecutionStacks(container); - return container.waitFor(TIMEOUT_MS); + return container.waitFor(TIMEOUT_MS, waitFunction); } public static List collectFrames(@NotNull XDebugSession session) { @@ -146,13 +151,21 @@ public class XDebuggerTestUtil { } public static List collectFrames(XExecutionStack thread, long timeout) { - return collectFramesWithError(thread, timeout).first; + return collectFrames(thread, timeout, XDebuggerTestUtil::waitFor); + } + + public static List collectFrames(XExecutionStack thread, long timeout, BiFunction waitFunction) { + return collectFramesWithError(thread, timeout, waitFunction).first; } public static Pair, String> collectFramesWithError(XExecutionStack thread, long timeout) { + return collectFramesWithError(thread, timeout, XDebuggerTestUtil::waitFor); + } + + public static Pair, String> collectFramesWithError(XExecutionStack thread, long timeout, BiFunction waitFunction) { XTestStackFrameContainer container = new XTestStackFrameContainer(); thread.computeStackFrames(0, container); - return container.waitFor(timeout); + return container.waitFor(timeout, waitFunction); } public static Pair, XStackFrame> collectFramesWithSelected(@NotNull XDebugSession session, long timeout) { @@ -160,9 +173,13 @@ public class XDebuggerTestUtil { } public static Pair, XStackFrame> collectFramesWithSelected(XExecutionStack thread, long timeout) { + return collectFramesWithSelected(thread, timeout, XDebuggerTestUtil::waitFor); + } + + public static Pair, XStackFrame> collectFramesWithSelected(XExecutionStack thread, long timeout, BiFunction waitFunction) { XTestStackFrameContainer container = new XTestStackFrameContainer(); thread.computeStackFrames(0, container); - List all = container.waitFor(timeout).first; + List all = container.waitFor(timeout, waitFunction).first; return Pair.create(all, container.frameToSelect); } @@ -175,31 +192,50 @@ public class XDebuggerTestUtil { } public static List collectChildren(XValueContainer value) { + return collectChildren(value, XDebuggerTestUtil::waitFor); + } + + public static List collectChildren(XValueContainer value, BiFunction waitFunction) { XTestCompositeNode container = new XTestCompositeNode(); value.computeChildren(container); - return container.waitFor(TIMEOUT_MS).first; + + return container.waitFor(TIMEOUT_MS, waitFunction).first; } public static Pair evaluate(XDebugSession session, XExpression expression) { return evaluate(session, expression, TIMEOUT_MS); } + public static Pair evaluate(XDebugSession session, XExpression expression, BiFunction waitFunction) { + return evaluate(session, expression, TIMEOUT_MS, waitFunction); + } + public static Pair evaluate(XDebugSession session, String expression) { - return evaluate(session, XExpressionImpl.fromText(expression), TIMEOUT_MS); + return evaluate(session, expression, XDebuggerTestUtil::waitFor); + } + public static Pair evaluate(XDebugSession session, String expression, BiFunction waitFunction) { + return evaluate(session, XExpressionImpl.fromText(expression), TIMEOUT_MS, waitFunction); } public static Pair evaluate(XDebugSession session, String expression, long timeout) { - return evaluate(session, XExpressionImpl.fromText(expression), timeout); + return evaluate(session, expression, timeout, XDebuggerTestUtil::waitFor); + } + public static Pair evaluate(XDebugSession session, String expression, long timeout, BiFunction waitFunction) { + return evaluate(session, XExpressionImpl.fromText(expression), timeout, waitFunction); } private static Pair evaluate(XDebugSession session, XExpression expression, long timeout) { + return evaluate(session, expression, timeout, XDebuggerTestUtil::waitFor); + } + + private static Pair evaluate(XDebugSession session, XExpression expression, long timeout, BiFunction waitFunction) { XStackFrame frame = session.getCurrentStackFrame(); assertNotNull(frame); XDebuggerEvaluator evaluator = frame.getEvaluator(); assertNotNull(evaluator); XTestEvaluationCallback callback = new XTestEvaluationCallback(); evaluator.evaluate(expression, callback, session.getCurrentPosition()); - return callback.waitFor(timeout); + return callback.waitFor(timeout, waitFunction); } public static void waitForSwing() throws InterruptedException { @@ -226,16 +262,22 @@ public class XDebuggerTestUtil { } public static XTestValueNode computePresentation(@NotNull XValue value) { - return computePresentation(value, TIMEOUT_MS); + return computePresentation(value, XDebuggerTestUtil::waitFor); + } + public static XTestValueNode computePresentation(@NotNull XValue value, BiFunction waitFunction) { + return computePresentation(value, TIMEOUT_MS, waitFunction); } public static XTestValueNode computePresentation(XValue value, long timeout) { + return computePresentation(value, timeout, XDebuggerTestUtil::waitFor); + } + public static XTestValueNode computePresentation(XValue value, long timeout, BiFunction waitFunction) { XTestValueNode node = new XTestValueNode(); if (value instanceof XNamedValue) { node.myName = ((XNamedValue)value).getName(); } value.computePresentation(node, XValuePlace.TREE); - node.waitFor(timeout); + node.waitFor(timeout, waitFunction); return node; } @@ -244,7 +286,16 @@ public class XDebuggerTestUtil { @Nullable String type, @Nullable String value, @Nullable Boolean hasChildren) { - XTestValueNode node = computePresentation(var); + assertVariable(var, name, type, value, hasChildren, XDebuggerTestUtil::waitFor); + } + + public static void assertVariable(XValue var, + @Nullable String name, + @Nullable String type, + @Nullable String value, + @Nullable Boolean hasChildren, + BiFunction waitFunction) { + XTestValueNode node = computePresentation(var, waitFunction); if (name != null) assertEquals(name, node.myName); if (type != null) assertEquals(type, node.myType); @@ -299,7 +350,16 @@ public class XDebuggerTestUtil { @Nullable String type, @Nullable @Language("RegExp") String valuePattern, @Nullable Boolean hasChildren) { - XTestValueNode node = computePresentation(var); + assertVariableValueMatches(var, name, type, valuePattern, hasChildren, XDebuggerTestUtil::waitFor); + } + + public static void assertVariableValueMatches(@NotNull XValue var, + @Nullable String name, + @Nullable String type, + @Nullable @Language("RegExp") String valuePattern, + @Nullable Boolean hasChildren, + BiFunction waitFunction) { + XTestValueNode node = computePresentation(var, waitFunction); if (name != null) assertEquals(name, node.myName); if (type != null) assertEquals(type, node.myType); if (valuePattern != null) { @@ -317,7 +377,14 @@ public class XDebuggerTestUtil { public static void assertVariableTypeMatches(@NotNull XValue var, @Nullable String name, @Nullable @Language("RegExp") String typePattern) { - XTestValueNode node = computePresentation(var); + assertVariableTypeMatches(var, name, typePattern, XDebuggerTestUtil::waitFor); + } + + public static void assertVariableTypeMatches(@NotNull XValue var, + @Nullable String name, + @Nullable @Language("RegExp") String typePattern, + @NotNull BiFunction waitFunction) { + XTestValueNode node = computePresentation(var, waitFunction); if (name != null) { assertEquals(name, node.myName); } @@ -328,7 +395,13 @@ public class XDebuggerTestUtil { public static void assertVariableFullValue(@NotNull XValue var, @Nullable String value) throws Exception { - XTestValueNode node = computePresentation(var); + assertVariableFullValue(var, value, XDebuggerTestUtil::waitFor); + } + + public static void assertVariableFullValue(@NotNull XValue var, + @Nullable String value, + @NotNull BiFunction waitFunction) throws Exception { + XTestValueNode node = computePresentation(var, waitFunction); if (value == null) { assertNull("full value evaluator should be null", node.myFullValueEvaluator); diff --git a/platform/xdebugger-impl/testSrc/com/intellij/xdebugger/XTestContainer.java b/platform/xdebugger-impl/testSrc/com/intellij/xdebugger/XTestContainer.java index 57ac8996651c..9f3c86b5afc6 100644 --- a/platform/xdebugger-impl/testSrc/com/intellij/xdebugger/XTestContainer.java +++ b/platform/xdebugger-impl/testSrc/com/intellij/xdebugger/XTestContainer.java @@ -13,6 +13,7 @@ import org.jetbrains.annotations.Nullable; import javax.swing.*; import java.util.List; import java.util.concurrent.Semaphore; +import java.util.function.BiFunction; public class XTestContainer { private final List myChildren = new SmartList<>(); @@ -41,7 +42,11 @@ public class XTestContainer { } public Pair, String> waitFor(long timeoutMs) { - if (!XDebuggerTestUtil.waitFor(myFinished, timeoutMs)) { + return waitFor(timeoutMs, (semaphore, timeout) -> XDebuggerTestUtil.waitFor(myFinished, timeout)); + } + + public Pair, String> waitFor(long timeoutMs, BiFunction waitFunction) { + if (!waitFunction.apply(myFinished, timeoutMs)) { throw new AssertionError("Waiting timed out"); } diff --git a/platform/xdebugger-impl/testSrc/com/intellij/xdebugger/XTestEvaluationCallback.java b/platform/xdebugger-impl/testSrc/com/intellij/xdebugger/XTestEvaluationCallback.java index 6425a685a604..0d298ad9a945 100644 --- a/platform/xdebugger-impl/testSrc/com/intellij/xdebugger/XTestEvaluationCallback.java +++ b/platform/xdebugger-impl/testSrc/com/intellij/xdebugger/XTestEvaluationCallback.java @@ -21,6 +21,7 @@ import com.intellij.xdebugger.impl.ui.tree.nodes.XEvaluationCallbackBase; import org.jetbrains.annotations.NotNull; import java.util.concurrent.Semaphore; +import java.util.function.BiFunction; import static org.junit.Assert.*; @@ -42,7 +43,11 @@ public class XTestEvaluationCallback extends XEvaluationCallbackBase { } public Pair waitFor(long timeoutInMilliseconds) { - assertTrue("timed out", XDebuggerTestUtil.waitFor(myFinished, timeoutInMilliseconds)); + return waitFor(timeoutInMilliseconds, XDebuggerTestUtil::waitFor); + } + + public Pair waitFor(long timeoutInMilliseconds, BiFunction waitFunction) { + assertTrue("timed out", waitFunction.apply(myFinished, timeoutInMilliseconds)); return Pair.create(myResult, myErrorMessage); } } diff --git a/platform/xdebugger-impl/testSrc/com/intellij/xdebugger/XTestValueNode.java b/platform/xdebugger-impl/testSrc/com/intellij/xdebugger/XTestValueNode.java index 32c78f2533c9..95d5b2e5e0eb 100644 --- a/platform/xdebugger-impl/testSrc/com/intellij/xdebugger/XTestValueNode.java +++ b/platform/xdebugger-impl/testSrc/com/intellij/xdebugger/XTestValueNode.java @@ -12,6 +12,7 @@ import org.jetbrains.annotations.Nullable; import javax.swing.*; import java.util.concurrent.Semaphore; +import java.util.function.BiFunction; public class XTestValueNode extends XValueNodePresentationConfigurator.ConfigurableXValueNodeImpl { public Icon myIcon; @@ -42,7 +43,10 @@ public class XTestValueNode extends XValueNodePresentationConfigurator.Configura } public void waitFor(long timeoutInMillis) { - if (!XDebuggerTestUtil.waitFor(myFinished, timeoutInMillis)) { + waitFor(timeoutInMillis, XDebuggerTestUtil::waitFor); + } + public void waitFor(long timeoutInMillis, BiFunction waitFunction) { + if (!waitFunction.apply(myFinished, timeoutInMillis)) { throw new AssertionError("Waiting timed out"); } }