mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-30 04:15: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.IIndexManager;
|
||||||
import org.eclipse.cdt.core.index.IndexFilter;
|
import org.eclipse.cdt.core.index.IndexFilter;
|
||||||
import org.eclipse.cdt.core.model.CoreModel;
|
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.ICProject;
|
||||||
import org.eclipse.cdt.core.model.IElementChangedListener;
|
|
||||||
import org.eclipse.cdt.core.testplugin.CProjectHelper;
|
import org.eclipse.cdt.core.testplugin.CProjectHelper;
|
||||||
import org.eclipse.cdt.core.testplugin.util.TestSourceReader;
|
import org.eclipse.cdt.core.testplugin.util.TestSourceReader;
|
||||||
import org.eclipse.cdt.internal.core.pdom.indexer.IndexerPreferences;
|
import org.eclipse.cdt.internal.core.pdom.indexer.IndexerPreferences;
|
||||||
|
@ -94,48 +92,6 @@ public class TeamSharedIndexTest extends IndexTestBase {
|
||||||
mj.dispose();
|
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 {
|
private ICProject recreateProject(final String prjName) throws Exception {
|
||||||
final IWorkspace workspace = ResourcesPlugin.getWorkspace();
|
final IWorkspace workspace = ResourcesPlugin.getWorkspace();
|
||||||
|
|
|
@ -66,41 +66,44 @@ public class PDOMTestBase extends BaseTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ICProject createProject(String folderName, final boolean cpp) throws CoreException {
|
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];
|
final ICProject cprojects[] = new ICProject[1];
|
||||||
workspace.run(new IWorkspaceRunnable() {
|
ModelJoiner mj= new ModelJoiner();
|
||||||
public void run(IProgressMonitor monitor) throws CoreException {
|
try {
|
||||||
// Create the project
|
// Create the project
|
||||||
ICProject cproject= cpp ? CProjectHelper.createCCProject(projectName, null, IPDOMManager.ID_NO_INDEXER)
|
projectName = "ProjTest_" + System.currentTimeMillis();
|
||||||
: CProjectHelper.createCProject(projectName, null, IPDOMManager.ID_NO_INDEXER);
|
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
|
// Import the files at the root
|
||||||
ImportOperation importOp = new ImportOperation(cproject.getProject().getFullPath(),
|
ImportOperation importOp = new ImportOperation(cproject.getProject().getFullPath(),
|
||||||
rootDir, FileSystemStructureProvider.INSTANCE, new IOverwriteQuery() {
|
rootDir, FileSystemStructureProvider.INSTANCE, new IOverwriteQuery() {
|
||||||
public String queryOverwrite(String pathString) {
|
public String queryOverwrite(String pathString) {
|
||||||
return IOverwriteQuery.ALL;
|
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);
|
cprojects[0] = cproject;
|
||||||
try {
|
|
||||||
importOp.run(monitor);
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new CoreException(new Status(IStatus.ERROR, CTestPlugin.PLUGIN_ID, 0, "Import Interrupted", e));
|
|
||||||
}
|
}
|
||||||
|
}, null);
|
||||||
cprojects[0] = cproject;
|
mj.join();
|
||||||
}
|
// Index the project
|
||||||
}, null);
|
CCorePlugin.getIndexManager().setIndexerId(cprojects[0], IPDOMManager.ID_FAST_INDEXER);
|
||||||
|
// wait until the indexer is done
|
||||||
// Index the project
|
assertTrue(CCorePlugin.getIndexManager().joinIndexer(360000, new NullProgressMonitor()));
|
||||||
CCorePlugin.getIndexManager().setIndexerId(cprojects[0], IPDOMManager.ID_FAST_INDEXER);
|
} finally {
|
||||||
// wait until the indexer is done
|
mj.dispose();
|
||||||
assertTrue(CCorePlugin.getIndexManager().joinIndexer(360000, new NullProgressMonitor()));
|
}
|
||||||
|
|
||||||
return cprojects[0];
|
return cprojects[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,10 @@ import junit.framework.TestResult;
|
||||||
import junit.framework.TestSuite;
|
import junit.framework.TestSuite;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.CCorePlugin;
|
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.ILogListener;
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
import org.eclipse.core.runtime.IStatus;
|
import org.eclipse.core.runtime.IStatus;
|
||||||
|
@ -187,4 +191,50 @@ public class BaseTestCase extends TestCase {
|
||||||
public void setExpectedNumberOfLoggedNonOKStatusObjects(int count) {
|
public void setExpectedNumberOfLoggedNonOKStatusObjects(int count) {
|
||||||
fExpectedLoggedNonOK= 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