Source:
<code>public void testBug546710_ConsoleCreationRaceCondition() throws Exception { <START> DebugUIPlugin.getDefault().getPreferenceStore().setValue(IDebugUIConstants.PREF_AUTO_REMOVE_OLD_LAUNCHES, <END> true); final ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager(); for (ILaunch existingLaunch : launchManager.getLaunches()) { assertTrue("Found existing not terminated launch. This should not happen and can interfere this test. Check for leakages in previous run tests.", existingLaunch.isTerminated()); launchManager.removeLaunch(existingLaunch); } final MockProcess mockProcess1 = new MockProcess(0); final IProcess process1 = mockProcess1.toRuntimeProcess("FirstMockProcess"); final MockProcess mockProcess2 = new MockProcess(0); final IProcess process2 = mockProcess2.toRuntimeProcess("SecondMockProcess"); try { Job.getJobManager().suspend(); launchManager.addLaunch(process1.getLaunch()); launchManager.addLaunch(process2.getLaunch()); } finally { Job.getJobManager().resume(); } ProcessConsoleManager processConsoleManager = DebugUIPlugin.getDefault().getProcessConsoleManager(); TestUtil.waitForJobs(getName(), 0, 10000); int openConsoles = 0; if (processConsoleManager.getConsole(process1) != null) { openConsoles++; } if (processConsoleManager.getConsole(process2) != null) { openConsoles++; } assertEquals("ProcessConsoleManager and LaunchManager got out of sync.", openConsoles, launchManager.getLaunches().length); final ConsoleRemoveAllTerminatedAction removeAction = new ConsoleRemoveAllTerminatedAction(); assertTrue("Remove terminated action should be enabled.", removeAction.isEnabled() || launchManager.getLaunches().length == 0); removeAction.run(); TestUtil.waitForJobs(getName(), 0, 10000); assertNull("First console not removed.", processConsoleManager.getConsole(process1)); assertNull("Second console not removed.", processConsoleManager.getConsole(process1)); }</code><technical_language>This read value, remember re-set - teardown in finally block. test change environment</technical_language>

Target:
public void testBug546710_ConsoleCreationRaceCondition() throws Exception { final ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager(); for (ILaunch existingLaunch : launchManager.getLaunches()) { assertTrue("Found existing not terminated launch. This should not happen and can interfere this test. Check for leakages in previous run tests.", existingLaunch.isTerminated()); launchManager.removeLaunch(existingLaunch); } final MockProcess mockProcess1 = new MockProcess(0); final IProcess process1 = mockProcess1.toRuntimeProcess("FirstMockProcess"); final MockProcess mockProcess2 = new MockProcess(0); final IProcess process2 = mockProcess2.toRuntimeProcess("SecondMockProcess"); final boolean prefRemoveOldLaunches = DebugUIPlugin.getDefault().getPreferenceStore().getBoolean(IDebugUIConstants.PREF_AUTO_REMOVE_OLD_LAUNCHES); try { DebugUIPlugin.getDefault().getPreferenceStore().setValue(IDebugUIConstants.PREF_AUTO_REMOVE_OLD_LAUNCHES, true); Job.getJobManager().suspend(); launchManager.addLaunch(process1.getLaunch()); launchManager.addLaunch(process2.getLaunch()); } finally { Job.getJobManager().resume(); DebugUIPlugin.getDefault().getPreferenceStore().setValue(IDebugUIConstants.PREF_AUTO_REMOVE_OLD_LAUNCHES, prefRemoveOldLaunches); } ProcessConsoleManager processConsoleManager = DebugUIPlugin.getDefault().getProcessConsoleManager(); TestUtil.waitForJobs(getName(), 0, 10000); int openConsoles = 0; if (processConsoleManager.getConsole(process1) != null) { openConsoles++; } if (processConsoleManager.getConsole(process2) != null) { openConsoles++; } assertEquals("ProcessConsoleManager and LaunchManager got out of sync.", openConsoles, launchManager.getLaunches().length); final ConsoleRemoveAllTerminatedAction removeAction = new ConsoleRemoveAllTerminatedAction(); assertTrue("Remove terminated action should be enabled.", removeAction.isEnabled() || launchManager.getLaunches().length == 0); removeAction.run(); TestUtil.waitForJobs(getName(), 0, 10000); assertNull("First console not removed.", processConsoleManager.getConsole(process1)); assertNull("Second console not removed.", processConsoleManager.getConsole(process1)); }