From 97f8327c2abce0ae57c81b8523f2f77ca39bb516 Mon Sep 17 00:00:00 2001 From: Andrew Ferguson Date: Thu, 14 Jun 2007 10:32:54 +0000 Subject: [PATCH] fix intermittent failures in PDOM tests --- .../index/tests/TeamSharedIndexTest.java | 44 ------------- .../cdt/internal/pdom/tests/PDOMTestBase.java | 65 ++++++++++--------- .../core/testplugin/util/BaseTestCase.java | 50 ++++++++++++++ 3 files changed, 84 insertions(+), 75 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/TeamSharedIndexTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/TeamSharedIndexTest.java index aae7950cbd4..0f868379e77 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/TeamSharedIndexTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/TeamSharedIndexTest.java @@ -27,9 +27,7 @@ import org.eclipse.cdt.core.index.IIndex; import org.eclipse.cdt.core.index.IIndexManager; import org.eclipse.cdt.core.index.IndexFilter; import org.eclipse.cdt.core.model.CoreModel; -import org.eclipse.cdt.core.model.ElementChangedEvent; import org.eclipse.cdt.core.model.ICProject; -import org.eclipse.cdt.core.model.IElementChangedListener; import org.eclipse.cdt.core.testplugin.CProjectHelper; import org.eclipse.cdt.core.testplugin.util.TestSourceReader; import org.eclipse.cdt.internal.core.pdom.indexer.IndexerPreferences; @@ -94,48 +92,6 @@ public class TeamSharedIndexTest extends IndexTestBase { mj.dispose(); } } - - static class ModelJoiner implements IElementChangedListener { - private boolean[] changed= new boolean[1]; - - public ModelJoiner() { - CoreModel.getDefault().addElementChangedListener(this); - } - - public void clear() { - synchronized (changed) { - changed[0]= false; - changed.notifyAll(); - } - } - - public void join() throws CoreException { - try { - synchronized(changed) { - while(!changed[0]) { - changed.wait(); - } - } - } catch(InterruptedException ie) { - throw new CoreException(CCorePlugin.createStatus("Interrupted", ie)); - } - } - - public void dispose() { - CoreModel.getDefault().removeElementChangedListener(this); - } - - public void elementChanged(ElementChangedEvent event) { - // Only respond to post change events - if (event.getType() != ElementChangedEvent.POST_CHANGE) - return; - - synchronized (changed) { - changed[0]= true; - changed.notifyAll(); - } - } - } private ICProject recreateProject(final String prjName) throws Exception { final IWorkspace workspace = ResourcesPlugin.getWorkspace(); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMTestBase.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMTestBase.java index 6b641241757..6db543ae67f 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMTestBase.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMTestBase.java @@ -66,41 +66,44 @@ public class PDOMTestBase extends BaseTestCase { } protected ICProject createProject(String folderName, final boolean cpp) throws CoreException { - - // Create the project - projectName = "ProjTest_" + System.currentTimeMillis(); - final File rootDir = CTestPlugin.getDefault().getFileInPlugin(rootPath.append(folderName)); - final IWorkspace workspace = ResourcesPlugin.getWorkspace(); final ICProject cprojects[] = new ICProject[1]; - workspace.run(new IWorkspaceRunnable() { - public void run(IProgressMonitor monitor) throws CoreException { - // Create the project - ICProject cproject= cpp ? CProjectHelper.createCCProject(projectName, null, IPDOMManager.ID_NO_INDEXER) - : CProjectHelper.createCProject(projectName, null, IPDOMManager.ID_NO_INDEXER); + ModelJoiner mj= new ModelJoiner(); + try { + // Create the project + projectName = "ProjTest_" + System.currentTimeMillis(); + final File rootDir = CTestPlugin.getDefault().getFileInPlugin(rootPath.append(folderName)); + final IWorkspace workspace = ResourcesPlugin.getWorkspace(); + workspace.run(new IWorkspaceRunnable() { + public void run(IProgressMonitor monitor) throws CoreException { + // Create the project + ICProject cproject= cpp ? CProjectHelper.createCCProject(projectName, null, IPDOMManager.ID_NO_INDEXER) + : CProjectHelper.createCProject(projectName, null, IPDOMManager.ID_NO_INDEXER); - // Import the files at the root - ImportOperation importOp = new ImportOperation(cproject.getProject().getFullPath(), - rootDir, FileSystemStructureProvider.INSTANCE, new IOverwriteQuery() { - public String queryOverwrite(String pathString) { - return IOverwriteQuery.ALL; + // Import the files at the root + ImportOperation importOp = new ImportOperation(cproject.getProject().getFullPath(), + rootDir, FileSystemStructureProvider.INSTANCE, new IOverwriteQuery() { + public String queryOverwrite(String pathString) { + return IOverwriteQuery.ALL; + } + }); + importOp.setCreateContainerStructure(false); + try { + importOp.run(monitor); + } catch (Exception e) { + throw new CoreException(new Status(IStatus.ERROR, CTestPlugin.PLUGIN_ID, 0, "Import Interrupted", e)); } - }); - importOp.setCreateContainerStructure(false); - try { - importOp.run(monitor); - } catch (Exception e) { - throw new CoreException(new Status(IStatus.ERROR, CTestPlugin.PLUGIN_ID, 0, "Import Interrupted", e)); + + cprojects[0] = cproject; } - - cprojects[0] = cproject; - } - }, null); - - // Index the project - CCorePlugin.getIndexManager().setIndexerId(cprojects[0], IPDOMManager.ID_FAST_INDEXER); - // wait until the indexer is done - assertTrue(CCorePlugin.getIndexManager().joinIndexer(360000, new NullProgressMonitor())); - + }, null); + mj.join(); + // Index the project + CCorePlugin.getIndexManager().setIndexerId(cprojects[0], IPDOMManager.ID_FAST_INDEXER); + // wait until the indexer is done + assertTrue(CCorePlugin.getIndexManager().joinIndexer(360000, new NullProgressMonitor())); + } finally { + mj.dispose(); + } return cprojects[0]; } diff --git a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/util/BaseTestCase.java b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/util/BaseTestCase.java index 006d5755101..571017f02af 100644 --- a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/util/BaseTestCase.java +++ b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/util/BaseTestCase.java @@ -28,6 +28,10 @@ import junit.framework.TestResult; import junit.framework.TestSuite; import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.model.CoreModel; +import org.eclipse.cdt.core.model.ElementChangedEvent; +import org.eclipse.cdt.core.model.IElementChangedListener; +import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.ILogListener; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; @@ -187,4 +191,50 @@ public class BaseTestCase extends TestCase { public void setExpectedNumberOfLoggedNonOKStatusObjects(int count) { fExpectedLoggedNonOK= count; } + + /** + * Some test steps need synchronizing against a CModel event. This class + * is a very basic means of doing that. + */ + static protected class ModelJoiner implements IElementChangedListener { + private boolean[] changed= new boolean[1]; + + public ModelJoiner() { + CoreModel.getDefault().addElementChangedListener(this); + } + + public void clear() { + synchronized (changed) { + changed[0]= false; + changed.notifyAll(); + } + } + + public void join() throws CoreException { + try { + synchronized(changed) { + while(!changed[0]) { + changed.wait(); + } + } + } catch(InterruptedException ie) { + throw new CoreException(CCorePlugin.createStatus("Interrupted", ie)); + } + } + + public void dispose() { + CoreModel.getDefault().removeElementChangedListener(this); + } + + public void elementChanged(ElementChangedEvent event) { + // Only respond to post change events + if (event.getType() != ElementChangedEvent.POST_CHANGE) + return; + + synchronized (changed) { + changed[0]= true; + changed.notifyAll(); + } + } + } } \ No newline at end of file