Skip to content

Commit 605ef63

Browse files
committed
Improve failures message in failing ProcessConsoleManagerTest #596
Provide more debug information on random test failures for ProcessConsoleManagerTest#testBug546710_ConsoleCreationRaceCondition(). Contributes to #596
1 parent c04ef27 commit 605ef63

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

debug/org.eclipse.debug.tests/src/org/eclipse/debug/tests/console/ProcessConsoleManagerTests.java

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,17 @@
1313
*******************************************************************************/
1414
package org.eclipse.debug.tests.console;
1515

16+
import static java.util.stream.Collectors.joining;
17+
import static org.hamcrest.MatcherAssert.assertThat;
18+
import static org.hamcrest.Matchers.hasSize;
1619
import static org.junit.Assert.assertEquals;
1720
import static org.junit.Assert.assertNull;
1821
import static org.junit.Assert.assertTrue;
1922

23+
import java.util.HashSet;
24+
import java.util.Set;
25+
import java.util.stream.Stream;
26+
2027
import org.eclipse.core.runtime.IStatus;
2128
import org.eclipse.core.runtime.jobs.Job;
2229
import org.eclipse.debug.core.DebugPlugin;
@@ -33,6 +40,7 @@
3340
import org.eclipse.debug.tests.TestUtil;
3441
import org.eclipse.debug.ui.IDebugUIConstants;
3542
import org.eclipse.ui.console.ConsolePlugin;
43+
import org.eclipse.ui.console.IConsole;
3644
import org.eclipse.ui.console.IConsoleManager;
3745
import org.junit.Test;
3846

@@ -100,23 +108,29 @@ public void testBug546710_ConsoleCreationRaceCondition() throws Exception {
100108
setPreference(DebugUIPlugin.getDefault().getPreferenceStore(), IDebugUIConstants.PREF_AUTO_REMOVE_OLD_LAUNCHES, true);
101109
// Stop the JobManager to reliable trigger the tested race
102110
// condition.
111+
TestUtil.waitForJobs(name.getMethodName(), 0, 10000);
103112
Job.getJobManager().suspend();
104113
launchManager.addLaunch(process1.getLaunch());
105114
launchManager.addLaunch(process2.getLaunch());
106115
} finally {
107116
Job.getJobManager().resume();
108117
}
109118

110-
ProcessConsoleManager processConsoleManager = DebugUIPlugin.getDefault().getProcessConsoleManager();
111119
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<>();
113123
if (processConsoleManager.getConsole(process1) != null) {
114-
openConsoles++;
124+
openConsoles.add(processConsoleManager.getConsole(process1));
115125
}
116126
if (processConsoleManager.getConsole(process2) != null) {
117-
openConsoles++;
127+
openConsoles.add(processConsoleManager.getConsole(process2));
118128
}
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));
120134

121135
final ConsoleRemoveAllTerminatedAction removeAction = new ConsoleRemoveAllTerminatedAction();
122136
assertTrue("Remove terminated action should be enabled.", removeAction.isEnabled() || launchManager.getLaunches().length == 0);

0 commit comments

Comments
 (0)