Skip to content

Commit

Permalink
Change waiting mechanism ProcessConsoleTests.processTerminationTest e…
Browse files Browse the repository at this point in the history
…clipse-platform#548

Use "waitWhile" instead of "TestUtil.waitForJobs". The reason for this
is that "waitForJobs" might be too fast and it might happen before
DebugPlugin.fEventDispatchJob is even scheduled (the scheduling happens
in another thread). If that happens then the "fEventDispatchJob" never
even reaches the queue of the JobManager before "waitForJobs" is called
and the test
"ProcessConsoleTests.testProcessTerminationNotificationWithInputFile"
fails.

Also replace some hard-coded strings with the name of the current test
method (nitpicking).
  • Loading branch information
fedejeanne committed Jul 4, 2023
1 parent 77ba2f3 commit 9ad69b9
Showing 1 changed file with 3 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ public void testProcessTerminationNotificationWithInputFile() throws Exception {
assertTrue("Failed to prepare input file.", fileCreated);
try {
ILaunchConfigurationType launchType = DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurationType(LaunchConfigurationTests.ID_TEST_LAUNCH_TYPE);
ILaunchConfigurationWorkingCopy launchConfiguration = launchType.newInstance(null, "testProcessTerminationNotificationWithInputFromFile");
ILaunchConfigurationWorkingCopy launchConfiguration = launchType.newInstance(null, name.getMethodName());
launchConfiguration.setAttribute(IDebugUIConstants.ATTR_CAPTURE_STDIN_FILE, inFile.getAbsolutePath());
TestUtil.log(IStatus.INFO, name.getMethodName(), "Process terminates after Console is initialized.");
processTerminationTest(launchConfiguration, false);
Expand All @@ -267,7 +267,7 @@ public void testProcessTerminationNotificationWithInputFile() throws Exception {
public void processTerminationTest(ILaunchConfiguration launchConfig, boolean terminateBeforeConsoleInitialization) throws Exception {
final AtomicBoolean terminationSignaled = new AtomicBoolean(false);
final Process mockProcess = new MockProcess(null, null, terminateBeforeConsoleInitialization ? 0 : -1);
final IProcess process = DebugPlugin.newProcess(new Launch(launchConfig, ILaunchManager.RUN_MODE, null), mockProcess, "testProcessTerminationNotification");
final IProcess process = DebugPlugin.newProcess(new Launch(launchConfig, ILaunchManager.RUN_MODE, null), mockProcess, name.getMethodName());
@SuppressWarnings("restriction")
final org.eclipse.debug.internal.ui.views.console.ProcessConsole console = new org.eclipse.debug.internal.ui.views.console.ProcessConsole(process, new ConsoleColorProvider());
console.addPropertyChangeListener(event -> {
Expand All @@ -281,8 +281,7 @@ public void processTerminationTest(ILaunchConfiguration launchConfig, boolean te
if (mockProcess.isAlive()) {
mockProcess.destroy();
}
TestUtil.waitForJobs(name.getMethodName(), 50, 10000);
assertTrue("No console complete notification received.", terminationSignaled.get());
waitWhile(__ -> !terminationSignaled.get(), 10_000, __ -> "No console complete notification received.");
} finally {
consoleManager.removeConsoles(new IConsole[] { console });
TestUtil.waitForJobs(name.getMethodName(), 0, 10000);
Expand Down

0 comments on commit 9ad69b9

Please sign in to comment.