From 7e71d2b9b92f296d2a8cfdf4792a7e5fbbda8dcf Mon Sep 17 00:00:00 2001 From: Jonah Graham Date: Sat, 4 Mar 2017 00:02:27 +0000 Subject: [PATCH] Bug 512180 and Bug 501906: Minimize unstable tests As deleting launch configurations has a race condition that can cause them not to become undeletable, only delete them for the tests that they really need to be deleted for. Change-Id: I040cbc83ba29a9f3a791b0bf4348a3179792ec65 Signed-off-by: Jonah Graham --- .../tests/dsf/gdb/framework/BaseTestCase.java | 16 +++++++++++++++- .../tests/dsf/gdb/tests/SourceLookupTest.java | 2 ++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/framework/BaseTestCase.java b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/framework/BaseTestCase.java index 850459b6628..7aee5e59339 100644 --- a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/framework/BaseTestCase.java +++ b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/framework/BaseTestCase.java @@ -11,6 +11,7 @@ *******************************************************************************/ package org.eclipse.cdt.tests.dsf.gdb.framework; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -290,7 +291,7 @@ public class BaseTestCase { /** * Make sure we are starting with a clean/known state. That means no - * existing launches or launch configurations. + * existing launches. */ public void removeTeminatedLaunchesBeforeTest() throws CoreException { ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager(); @@ -303,11 +304,24 @@ public class BaseTestCase { if (launches.length > 0) { launchManager.removeLaunches(launches); } + } + /** + * Make sure we are starting with a clean/known state. That means no + * existing launch configurations. + * + * XXX: Bugs 512180 and 501906, limit this call to only those test that + * really need a clean state. This does not remove the race condition, but + * does improve it somewhat. + */ + public void removeLaunchConfigurationsBeforeTest() throws CoreException { + ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager(); ILaunchConfiguration[] launchConfigurations = launchManager.getLaunchConfigurations(); for (ILaunchConfiguration launchConfiguration : launchConfigurations) { launchConfiguration.delete(); } + + assertEquals("Failed to delete launch configurations", 0, launchManager.getLaunchConfigurations().length); } @Before diff --git a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/SourceLookupTest.java b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/SourceLookupTest.java index 05ec236d6b3..60ed7864470 100644 --- a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/SourceLookupTest.java +++ b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/SourceLookupTest.java @@ -954,11 +954,13 @@ public class SourceLookupTest extends BaseParametrizedTestCase { @Test public void sourceFinderMappingAC_LaunchConfig() throws Throwable { + removeLaunchConfigurationsBeforeTest(); sourceFinderMappingAC_LaunchConfigHelper(false); } @Test public void sourceFinderSubstituteAC_LaunchConfig() throws Throwable { + removeLaunchConfigurationsBeforeTest(); sourceFinderMappingAC_LaunchConfigHelper(true); }