Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrey Loskutov2016-10-24 21:33:22 +0000
committerAndrey Loskutov2016-11-09 12:20:53 +0000
commit66da2950cc347953d38ae225f82b5f23f5e960e7 (patch)
treea701ca5a3456d6c4ea116fc613b7e4926670f38c
parent55be2b2039f8c5815b319fed1f3f7c62f122130c (diff)
downloadeclipse.platform.debug-66da2950cc347953d38ae225f82b5f23f5e960e7.tar.gz
eclipse.platform.debug-66da2950cc347953d38ae225f82b5f23f5e960e7.tar.xz
eclipse.platform.debug-66da2950cc347953d38ae225f82b5f23f5e960e7.zip
Change-Id: I54c8dbbf8d26234bd5f07c4a47bf0224e2e3eef6 Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
-rw-r--r--org.eclipse.debug.tests/src/org/eclipse/debug/tests/console/ConsoleManagerTests.java40
1 files changed, 36 insertions, 4 deletions
diff --git a/org.eclipse.debug.tests/src/org/eclipse/debug/tests/console/ConsoleManagerTests.java b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/console/ConsoleManagerTests.java
index 02fdf43d2..0e3d7fd4d 100644
--- a/org.eclipse.debug.tests/src/org/eclipse/debug/tests/console/ConsoleManagerTests.java
+++ b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/console/ConsoleManagerTests.java
@@ -53,6 +53,8 @@ public class ConsoleManagerTests extends TestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
+ assertNotNull("Must run in UI thread, but was in: " + Thread.currentThread().getName(), //$NON-NLS-1$
+ Display.getCurrent());
count = 20;
latch = new CountDownLatch(count);
executorService = Executors.newFixedThreadPool(count);
@@ -121,26 +123,55 @@ public class ConsoleManagerTests extends TestCase {
for (ConsoleMock console : consoles) {
showConsole(console);
}
+ System.out.println("All tasks scheduled, processing UI events now..."); //$NON-NLS-1$
+ processUIEvents(1000);
+
// Console manager starts a job with delay, let wait for him a bit
+ System.out.println("Waiting on jobs now..."); //$NON-NLS-1$
waitForJobs();
// Give UI a chance to proceed pending console manager jobs
+ System.out.println("Done with jobs, processing UI events again..."); //$NON-NLS-1$
processUIEvents(3000);
executorService.shutdown();
- executorService.awaitTermination(1, TimeUnit.MINUTES);
+
+ System.out.println("Waiting on execution service to finish..."); //$NON-NLS-1$
+ boolean OK = waitForExecutorService();
+ if (!OK) {
+ System.out.println("Timed out..."); //$NON-NLS-1$
+ processUIEvents(10000);
+
+ // timeout?
+ assertTrue("Timeout occurred while waiting on console to be shown", //$NON-NLS-1$
+ waitForExecutorService());
+ } else {
+ System.out.println("Done waiting on execution service to finish"); //$NON-NLS-1$
+ }
int shown = ConsoleMock.allShownConsoles.intValue();
assertEquals("Only " + shown + " consoles were shown from " + count, count, shown); //$NON-NLS-1$ //$NON-NLS-2$
}
+ private boolean waitForExecutorService() throws InterruptedException {
+ for (int i = 0; i < 60; i++) {
+ if (executorService.awaitTermination(1, TimeUnit.SECONDS)) {
+ return true;
+ }
+ processUIEvents(100);
+ }
+ return false;
+ }
+
private void processUIEvents(final long millis) {
long start = System.currentTimeMillis();
while (System.currentTimeMillis() - start < millis) {
- PlatformUI.getWorkbench().getDisplay().readAndDispatch();
+ while (PlatformUI.getWorkbench().getDisplay().readAndDispatch()) {
+ // loop untile the queue is empty
+ }
}
}
- private void waitForJobs() throws Exception {
+ private void waitForJobs() throws InterruptedException {
if (Display.getCurrent() == null) {
Thread.sleep(200);
} else {
@@ -167,8 +198,9 @@ public class ConsoleManagerTests extends TestCase {
System.out.println("Requesting to show: " + console); //$NON-NLS-1$
manager.showConsoleView(console);
waitForJobs();
- } catch (Exception e) {
+ } catch (InterruptedException e) {
e.printStackTrace();
+ Thread.interrupted();
}
}
});

Back to the top