diff options
author | Andrey Loskutov | 2016-10-24 21:33:22 +0000 |
---|---|---|
committer | Andrey Loskutov | 2016-11-09 12:20:53 +0000 |
commit | 66da2950cc347953d38ae225f82b5f23f5e960e7 (patch) | |
tree | a701ca5a3456d6c4ea116fc613b7e4926670f38c | |
parent | 55be2b2039f8c5815b319fed1f3f7c62f122130c (diff) | |
download | eclipse.platform.debug-I20161109-2000.tar.gz eclipse.platform.debug-I20161109-2000.tar.xz eclipse.platform.debug-I20161109-2000.zip |
Bug 489546 - still trying to stabilize the test caseY20161124-1000Y20161117-1000Y20161110-1000I20161130-2000I20161129-2330I20161129-2000I20161128-2000I20161128-0600I20161128-0330I20161127-2000I20161127-1300I20161126-2000I20161126-0815I20161125-2000I20161124-2000I20161123-2000I20161122-2000I20161121-2000I20161120-2000I20161119-2000I20161118-2000I20161117-2000I20161116-2000I20161115-2000I20161114-2000I20161114-0355I20161113-2000I20161112-2000I20161112-0405I20161111-2000I20161111-1220I20161111-0900I20161111-0740I20161111-0510I20161110-2030I20161110-1630I20161110-1225I20161110-1130I20161110-0710I20161110-0510I20161109-2000
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.java | 40 |
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(); } } }); |