From d5d9a9ca34b282d8f94cccf160a6fe34b4dd7dee Mon Sep 17 00:00:00 2001 From: John Cortell Date: Mon, 1 Mar 2010 23:47:08 +0000 Subject: [PATCH] Improve waitForBreakpointEvent() --- .../dsf/gdb/tests/MIBreakpointsTest.java | 32 +++++++++++++++---- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/MIBreakpointsTest.java b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/MIBreakpointsTest.java index 0c597a45cc0..3c3fedc39bd 100644 --- a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/MIBreakpointsTest.java +++ b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/MIBreakpointsTest.java @@ -309,20 +309,38 @@ public class MIBreakpointsTest extends BaseTestCase { return count; } - // Suspends the thread until an event is flagged - // NOTE: too simple for real life but good enough for this test suite - private void waitForBreakpointEvent(int count) { + /** + * Suspends the calling thread until [count] number of breakpoint events + * have been received in the current test. NOTE: too simple for real life + * but good enough for this test suite + * + * @param count + * the number breakpoint events to wait for + * @param timeout + * max wait time, in milliseconds + */ + private void waitForBreakpointEvent(int count, int timeout) throws Exception { + long startMs = System.currentTimeMillis(); synchronized (lock) { // Make sure we don't wait forever, in case an event never // arrives. The test will check if everything was received - int loopIndex = 0; - while (fBreakpointEventCount < count && loopIndex++ < 4) { + while (fBreakpointEventCount < count) { try { - lock.wait(500); + lock.wait(30); } catch (InterruptedException ex) { } + if (System.currentTimeMillis() - startMs > timeout) { + throw new Exception("Timed out waiting for " + count + " breakpoint events to occur. Only " + fBreakpointEventCount + " occurred."); + } } - } + } + } + + /** + * Simplified variant that just waits up to two seconds + */ + private void waitForBreakpointEvent(int count) throws Exception { + waitForBreakpointEvent(count, TestsPlugin.massageTimeout(2000)); } // ========================================================================