mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-24 17:35:35 +02:00
fix intermittent failures in PDOM tests
This commit is contained in:
parent
ed3e376742
commit
97f8327c2a
3 changed files with 84 additions and 75 deletions
|
@ -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();
|
||||
|
|
|
@ -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];
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue