From 4ea6985013077f3caee479eec2bee90a97d296be Mon Sep 17 00:00:00 2001 From: Christian Walther Date: Thu, 18 Aug 2022 16:39:44 +0200 Subject: [PATCH 1/2] Fix flaky test testPersistentProperties Don't sleep for a hardcoded time but wait for the actual condition. 1000 ms was often insufficient on my system. --- .../tests/CProjectDescriptionSerializationTests.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/projectmodel/tests/CProjectDescriptionSerializationTests.java b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/projectmodel/tests/CProjectDescriptionSerializationTests.java index dbe9223c266..59278a6d6f2 100644 --- a/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/projectmodel/tests/CProjectDescriptionSerializationTests.java +++ b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/projectmodel/tests/CProjectDescriptionSerializationTests.java @@ -202,7 +202,6 @@ public void testPersistentProperties() throws Exception { coreModel.setProjectDescription(project, des); Assert.assertEquals(project, des.getProject()); - Thread.sleep(1000); // let scanner discovery participate try { QualifiedName pdomName = new QualifiedName(CCorePlugin.PLUGIN_ID, "pdomName"); QualifiedName activeCfg = new QualifiedName(CCorePlugin.PLUGIN_ID, "activeConfiguration"); @@ -210,6 +209,13 @@ public void testPersistentProperties() throws Exception { QualifiedName discoveredScannerConfigFileName = new QualifiedName(MakeCorePlugin.PLUGIN_ID, "discoveredScannerConfigFileName"); + // pdomName is set by indexer setup, which may still be postponed or not even + // scheduled yet, so we can't join the job. Just wait for the property to appear. + // (The other properties were set synchronously in setProjectDescription().) + for (int i = 0; i < 100 && !project.getPersistentProperties().containsKey(pdomName); i++) { + Thread.sleep(100); + } + assertTrue("pdomName", project.getPersistentProperties().containsKey(pdomName)); assertTrue("activeCfg", project.getPersistentProperties().containsKey(activeCfg)); assertTrue("discoveredScannerConfigFileName", From 7b2a2025420c34a8069d3cd20431966e309ed641 Mon Sep 17 00:00:00 2001 From: Christian Walther Date: Thu, 18 Aug 2022 17:32:31 +0200 Subject: [PATCH 2/2] Fix flaky tests in BuiltinSpecsDetectorTest testAbstractBuiltinSpecsDetector_EnvChangesGlobal did not properly clean up after itself, which caused testAbstractBuiltinSpecsDetector_EnvChangesConfiguration_1, testAbstractBuiltinSpecsDetector_EnvChangesConfiguration_2, and testAbstractBuiltinSpecsDetector_EnvChangesGlobal to fail when run for the second time in the same session. Running tests twice is not useful, but happens in Eclipse with a launch configuration set to run all tests in org.eclipse.cdt.managedbuilder.core.tests/tests - once directly and once through AllLanguageSettingsProvidersMBSTestSuite. I have not found any way of running every test exactly once in the GUI. --- .../settings/providers/tests/BuiltinSpecsDetectorTest.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/language/settings/providers/tests/BuiltinSpecsDetectorTest.java b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/language/settings/providers/tests/BuiltinSpecsDetectorTest.java index 7e643eb814b..c59788f7cf0 100644 --- a/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/language/settings/providers/tests/BuiltinSpecsDetectorTest.java +++ b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/language/settings/providers/tests/BuiltinSpecsDetectorTest.java @@ -851,6 +851,10 @@ public void testAbstractBuiltinSpecsDetector_EnvChangesGlobal() throws Exception assertEquals(true, provider.isExecuted()); assertEquals(ENV_SAMPLE_VALUE_2, provider.getSampleEnvVar()); + // clean up + vars.deleteAll(); + fUserSupplier.setWorkspaceEnvironment(vars); + // unregister listeners provider.unregisterListener(); }