diff options
author | Markus Duft | 2017-07-04 06:48:36 +0000 |
---|---|---|
committer | Markus Duft | 2017-07-04 06:48:36 +0000 |
commit | 37849a2dc5e14ae4a58bdc5699b77466db1b0b0a (patch) | |
tree | 4ab9d0634b0c52608efc0dfae95a028906037df7 /org.eclipse.debug.tests | |
parent | 19f71fda3568e05b39ec569758d21f02c1e6ab3c (diff) | |
download | eclipse.platform.debug-37849a2dc5e14ae4a58bdc5699b77466db1b0b0a.tar.gz eclipse.platform.debug-37849a2dc5e14ae4a58bdc5699b77466db1b0b0a.tar.xz eclipse.platform.debug-37849a2dc5e14ae4a58bdc5699b77466db1b0b0a.zip |
Bug 511607: Fix race condition in LaunchGroupTestsI20170709-2000I20170708-2000I20170707-2000I20170707-0530I20170706-2000I20170706-0630I20170705-2000I20170704-2000
LaunchGroup's .launch blocks until the awaited output is written. There
is a chance that the thread is unable to set the 'finished' boolean to
true before the test thread checks it. This can easily be reproduced
with a breakpoint at 'finished.set' in the second thread.
Change-Id: Iee056180a25e8078a6479bfef09de0359c78d298
Signed-off-by: Markus Duft <markus.duft@ssi-schaefer.com>
Diffstat (limited to 'org.eclipse.debug.tests')
-rw-r--r-- | org.eclipse.debug.tests/src/org/eclipse/debug/tests/launching/LaunchGroupTests.java | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/org.eclipse.debug.tests/src/org/eclipse/debug/tests/launching/LaunchGroupTests.java b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/launching/LaunchGroupTests.java index c17d13078..8799b6f60 100644 --- a/org.eclipse.debug.tests/src/org/eclipse/debug/tests/launching/LaunchGroupTests.java +++ b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/launching/LaunchGroupTests.java @@ -273,8 +273,10 @@ public class LaunchGroupTests extends AbstractLaunchTest { try { // wait some time before causing the group to continue Thread.sleep(2000); - attachListener.getStream().write("TestOutput"); //$NON-NLS-1$ - finished.set(true); + synchronized (finished) { + attachListener.getStream().write("TestOutput"); //$NON-NLS-1$ + finished.set(true); + } } catch (Exception e) { e.printStackTrace(); } @@ -286,7 +288,12 @@ public class LaunchGroupTests extends AbstractLaunchTest { // launching the group must block until the output is produced grp.launch(ILaunchManager.RUN_MODE, new NullProgressMonitor()); - getLaunchManager().removeLaunchListener(attachListener); + + synchronized (finished) { + // if the output appeared we have to wait for the thread to finish + // setting state. + getLaunchManager().removeLaunchListener(attachListener); + } assertTrue("thread did not finish", finished.get()); //$NON-NLS-1$ assertTrue("output was not awaited", (System.currentTimeMillis() - start) >= 2000); //$NON-NLS-1$ |