|
13 | 13 | *******************************************************************************/ |
14 | 14 | package org.eclipse.debug.tests.console; |
15 | 15 |
|
| 16 | +import static java.util.stream.Collectors.joining; |
| 17 | +import static org.hamcrest.MatcherAssert.assertThat; |
| 18 | +import static org.hamcrest.Matchers.hasSize; |
16 | 19 | import static org.junit.Assert.assertEquals; |
17 | 20 | import static org.junit.Assert.assertNull; |
18 | 21 | import static org.junit.Assert.assertTrue; |
19 | 22 |
|
| 23 | +import java.util.HashSet; |
| 24 | +import java.util.Set; |
| 25 | +import java.util.stream.Stream; |
| 26 | + |
20 | 27 | import org.eclipse.core.runtime.IStatus; |
21 | 28 | import org.eclipse.core.runtime.jobs.Job; |
22 | 29 | import org.eclipse.debug.core.DebugPlugin; |
|
33 | 40 | import org.eclipse.debug.tests.TestUtil; |
34 | 41 | import org.eclipse.debug.ui.IDebugUIConstants; |
35 | 42 | import org.eclipse.ui.console.ConsolePlugin; |
| 43 | +import org.eclipse.ui.console.IConsole; |
36 | 44 | import org.eclipse.ui.console.IConsoleManager; |
37 | 45 | import org.junit.Test; |
38 | 46 |
|
@@ -100,23 +108,29 @@ public void testBug546710_ConsoleCreationRaceCondition() throws Exception { |
100 | 108 | setPreference(DebugUIPlugin.getDefault().getPreferenceStore(), IDebugUIConstants.PREF_AUTO_REMOVE_OLD_LAUNCHES, true); |
101 | 109 | // Stop the JobManager to reliable trigger the tested race |
102 | 110 | // condition. |
| 111 | + TestUtil.waitForJobs(name.getMethodName(), 0, 10000); |
103 | 112 | Job.getJobManager().suspend(); |
104 | 113 | launchManager.addLaunch(process1.getLaunch()); |
105 | 114 | launchManager.addLaunch(process2.getLaunch()); |
106 | 115 | } finally { |
107 | 116 | Job.getJobManager().resume(); |
108 | 117 | } |
109 | 118 |
|
110 | | - ProcessConsoleManager processConsoleManager = DebugUIPlugin.getDefault().getProcessConsoleManager(); |
111 | 119 | TestUtil.waitForJobs(name.getMethodName(), 0, 10000); |
112 | | - int openConsoles = 0; |
| 120 | + ProcessConsoleManager processConsoleManager = DebugUIPlugin.getDefault().getProcessConsoleManager(); |
| 121 | + ILaunch[] launches = launchManager.getLaunches(); |
| 122 | + Set<IConsole> openConsoles = new HashSet<>(); |
113 | 123 | if (processConsoleManager.getConsole(process1) != null) { |
114 | | - openConsoles++; |
| 124 | + openConsoles.add(processConsoleManager.getConsole(process1)); |
115 | 125 | } |
116 | 126 | if (processConsoleManager.getConsole(process2) != null) { |
117 | | - openConsoles++; |
| 127 | + openConsoles.add(processConsoleManager.getConsole(process2)); |
118 | 128 | } |
119 | | - assertEquals("ProcessConsoleManager and LaunchManager got out of sync.", openConsoles, launchManager.getLaunches().length); |
| 129 | + |
| 130 | + String launchesString = Stream.of(launches).map(launch -> Stream.of(launch.getProcesses()).map(IProcess::getLabel).collect(joining(",", "[", "]"))).collect(joining()); |
| 131 | + String consolesString = openConsoles.stream().map(IConsole::getName).collect(joining()); |
| 132 | + String failureMessage = String.format("ProcessConsoleManager and LaunchManager got out of sync.\nLaunches: %s\nConsoles: %s", launchesString, consolesString); |
| 133 | + assertThat(failureMessage, openConsoles, hasSize(launches.length)); |
120 | 134 |
|
121 | 135 | final ConsoleRemoveAllTerminatedAction removeAction = new ConsoleRemoveAllTerminatedAction(); |
122 | 136 | assertTrue("Remove terminated action should be enabled.", removeAction.isEnabled() || launchManager.getLaunches().length == 0); |
|
0 commit comments