From 91d786f13eb4accb5c048c3b86a871b9609827c8 Mon Sep 17 00:00:00 2001 From: Marc Khouzam Date: Thu, 8 Oct 2009 20:07:53 +0000 Subject: [PATCH] [291754] Avoid race condition by waiting for the stopped event as soon as we have the launch --- .../tests/dsf/gdb/framework/BaseTestCase.java | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/framework/BaseTestCase.java b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/framework/BaseTestCase.java index a0d3551fbf3..6b04a2b814e 100644 --- a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/framework/BaseTestCase.java +++ b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/framework/BaseTestCase.java @@ -96,7 +96,18 @@ public class BaseTestCase { fLaunch = (GdbLaunch)lc.launch(ILaunchManager.DEBUG_MODE, new NullProgressMonitor()); assert fLaunch != null; - + + try { + // Also wait for the program to stop before allowing tests to start + // This should be done as soon as we have the launch, to avoid missing the Stopped + // event. If we do miss it, we'll just have a 10 second delay. + final ServiceEventWaitor eventWaitor = + new ServiceEventWaitor( + fLaunch.getSession(), + MIStoppedEvent.class); + fInitialStoppedEvent = eventWaitor.waitForEvent(10000); + } catch (Exception e) {} + // If we started a gdbserver add it to the launch to make sure it is killed at the end if (gdbserverProc != null) { DebugPlugin.newProcess(fLaunch, gdbserverProc, "gdbserver"); @@ -104,15 +115,6 @@ public class BaseTestCase { // Now initialize our SyncUtility, since we have the launcher SyncUtil.initialize(fLaunch.getSession()); - - try { - // Also wait for the program to stop before allowing tests to start - final ServiceEventWaitor eventWaitor = - new ServiceEventWaitor( - fLaunch.getSession(), - MIStoppedEvent.class); - fInitialStoppedEvent = eventWaitor.waitForEvent(10000); - } catch (Exception e) {} }