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.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;
|
||||
|
@ -95,48 +93,6 @@ public class TeamSharedIndexTest extends IndexTestBase {
|
|||
}
|
||||
}
|
||||
|
||||
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();
|
||||
ModelJoiner pj= new ModelJoiner();
|
||||
|
|
|
@ -66,12 +66,13 @@ public class PDOMTestBase extends BaseTestCase {
|
|||
}
|
||||
|
||||
protected ICProject createProject(String folderName, final boolean cpp) throws CoreException {
|
||||
|
||||
final ICProject cprojects[] = new ICProject[1];
|
||||
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();
|
||||
final ICProject cprojects[] = new ICProject[1];
|
||||
workspace.run(new IWorkspaceRunnable() {
|
||||
public void run(IProgressMonitor monitor) throws CoreException {
|
||||
// Create the project
|
||||
|
@ -95,12 +96,14 @@ public class PDOMTestBase extends BaseTestCase {
|
|||
cprojects[0] = cproject;
|
||||
}
|
||||
}, 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