mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Improved test for bug 196118, by James Blackburn
This commit is contained in:
parent
c47ff4d34f
commit
ae9cb76e8f
1 changed files with 39 additions and 14 deletions
|
@ -27,6 +27,7 @@ import org.eclipse.cdt.core.ICDescriptorOperation;
|
||||||
import org.eclipse.cdt.core.ICExtensionReference;
|
import org.eclipse.cdt.core.ICExtensionReference;
|
||||||
import org.eclipse.cdt.core.ICOwnerInfo;
|
import org.eclipse.cdt.core.ICOwnerInfo;
|
||||||
import org.eclipse.cdt.core.testplugin.CTestPlugin;
|
import org.eclipse.cdt.core.testplugin.CTestPlugin;
|
||||||
|
import org.eclipse.cdt.internal.core.CConfigBasedDescriptor;
|
||||||
import org.eclipse.cdt.internal.core.pdom.PDOMManager;
|
import org.eclipse.cdt.internal.core.pdom.PDOMManager;
|
||||||
import org.eclipse.core.resources.IProject;
|
import org.eclipse.core.resources.IProject;
|
||||||
import org.eclipse.core.resources.IProjectDescription;
|
import org.eclipse.core.resources.IProjectDescription;
|
||||||
|
@ -36,6 +37,7 @@ import org.eclipse.core.resources.IWorkspaceRunnable;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
import org.w3c.dom.Element;
|
import org.w3c.dom.Element;
|
||||||
|
import org.w3c.dom.Node;
|
||||||
import org.w3c.dom.NodeList;
|
import org.w3c.dom.NodeList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -77,10 +79,12 @@ public class CDescriptorTests extends TestCase {
|
||||||
|
|
||||||
TestSetup wrapper = new TestSetup(suite) {
|
TestSetup wrapper = new TestSetup(suite) {
|
||||||
|
|
||||||
|
@Override
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
oneTimeSetUp();
|
oneTimeSetUp();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected void tearDown() throws Exception {
|
protected void tearDown() throws Exception {
|
||||||
oneTimeTearDown();
|
oneTimeTearDown();
|
||||||
}
|
}
|
||||||
|
@ -157,6 +161,7 @@ public class CDescriptorTests extends TestCase {
|
||||||
fProject.close(null);
|
fProject.close(null);
|
||||||
fProject.open(null);
|
fProject.open(null);
|
||||||
Thread t= new Thread() {
|
Thread t= new Thread() {
|
||||||
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
CCorePlugin.getDefault().getCProjectDescription(fProject, true);
|
CCorePlugin.getDefault().getCProjectDescription(fProject, true);
|
||||||
|
@ -178,44 +183,48 @@ public class CDescriptorTests extends TestCase {
|
||||||
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=193503
|
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=193503
|
||||||
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=196118
|
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=196118
|
||||||
public void testConcurrentDescriptorCreation2() throws Exception {
|
public void testConcurrentDescriptorCreation2() throws Exception {
|
||||||
for (int i=0; i<20; ++i) {
|
int numElements = 0;
|
||||||
|
for (int i=0; i<200; ++i) {
|
||||||
|
final int indexi = i;
|
||||||
PDOMManager pdomMgr= (PDOMManager)CCorePlugin.getIndexManager();
|
PDOMManager pdomMgr= (PDOMManager)CCorePlugin.getIndexManager();
|
||||||
pdomMgr.shutdown();
|
pdomMgr.shutdown();
|
||||||
fProject.close(null);
|
fProject.close(null);
|
||||||
fProject.open(null);
|
fProject.open(null);
|
||||||
pdomMgr.startup().schedule();
|
pdomMgr.startup().schedule();
|
||||||
ICDescriptor desc= CCorePlugin.getDefault().getCProjectDescription(fProject, true);
|
ICDescriptor desc= CCorePlugin.getDefault().getCProjectDescription(fProject, true);
|
||||||
NodeList childNodes= desc.getProjectData("testElement").getChildNodes();
|
int lengthBefore= countChildElements(desc.getProjectData("testElement"));
|
||||||
int lengthBefore= childNodes.getLength();
|
|
||||||
final Throwable[] exception= new Throwable[10];
|
final Throwable[] exception= new Throwable[10];
|
||||||
Thread[] threads= new Thread[10];
|
Thread[] threads= new Thread[10];
|
||||||
for (int j = 0; j < 10; j++) {
|
for (int j = 0; j < 10; j++) {
|
||||||
final int index= j;
|
final int indexj = j;
|
||||||
Thread t= new Thread() {
|
Thread t= new Thread() {
|
||||||
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
ICDescriptorOperation operation= new ICDescriptorOperation() {
|
ICDescriptorOperation operation= new ICDescriptorOperation() {
|
||||||
public void execute(ICDescriptor descriptor, IProgressMonitor monitor) throws CoreException {
|
public void execute(ICDescriptor descriptor, IProgressMonitor monitor) throws CoreException {
|
||||||
assertFalse(descriptor.getConfigurationDescription().isReadOnly());
|
assertFalse(descriptor.getConfigurationDescription().isReadOnly());
|
||||||
try {
|
|
||||||
Thread.sleep(10);
|
|
||||||
} catch (InterruptedException exc) {
|
|
||||||
}
|
|
||||||
Element data = descriptor.getProjectData("testElement");
|
Element data = descriptor.getProjectData("testElement");
|
||||||
data.appendChild(data.getOwnerDocument().createElement("test"));
|
String test = "test"+(indexi*10 + indexj);
|
||||||
|
data.appendChild(data.getOwnerDocument().createElement(test));
|
||||||
assertFalse(descriptor.getConfigurationDescription().isReadOnly());
|
assertFalse(descriptor.getConfigurationDescription().isReadOnly());
|
||||||
|
// BUG196118 the model cached in memory doesn't reflect the contents of .cproject
|
||||||
|
//
|
||||||
|
// descriptor.saveProjectData() doesn't actually save despite what the API says
|
||||||
|
// see CConfigBasedDescriptor.fApplyOnChange
|
||||||
descriptor.saveProjectData();
|
descriptor.saveProjectData();
|
||||||
|
((CConfigBasedDescriptor)descriptor).apply(false);
|
||||||
|
// System.out.println("Saved " + test);
|
||||||
}};
|
}};
|
||||||
CCorePlugin.getDefault().getCDescriptorManager().runDescriptorOperation(fProject, operation, null);
|
CCorePlugin.getDefault().getCDescriptorManager().runDescriptorOperation(fProject, operation, null);
|
||||||
} catch (Throwable exc) {
|
} catch (Throwable exc) {
|
||||||
exception[index]= exc;
|
exception[indexj]= exc;
|
||||||
exc.printStackTrace();
|
exc.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
t.start();
|
t.start();
|
||||||
threads[j] = t;
|
threads[j] = t;
|
||||||
Thread.sleep(10);
|
|
||||||
}
|
}
|
||||||
for (int j = 0; j < threads.length; j++) {
|
for (int j = 0; j < threads.length; j++) {
|
||||||
if (threads[j] != null) {
|
if (threads[j] != null) {
|
||||||
|
@ -224,19 +233,35 @@ public class CDescriptorTests extends TestCase {
|
||||||
assertNull(exception[j]);
|
assertNull(exception[j]);
|
||||||
}
|
}
|
||||||
desc= CCorePlugin.getDefault().getCProjectDescription(fProject, true);
|
desc= CCorePlugin.getDefault().getCProjectDescription(fProject, true);
|
||||||
childNodes= desc.getProjectData("testElement").getChildNodes();
|
int lengthAfter = countChildElements(desc.getProjectData("testElement"));
|
||||||
int lengthAfter= childNodes.getLength();
|
assertEquals("Iteration count: " + i, threads.length, lengthAfter - lengthBefore);
|
||||||
assertEquals(threads.length, lengthAfter - lengthBefore);
|
|
||||||
|
|
||||||
fLastEvent = null;
|
fLastEvent = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Count the number of Node.ELEMENT_NODE elements which are a
|
||||||
|
* direct descendent of the parent Element.
|
||||||
|
* Other nodes (e.g. Text) are ignored
|
||||||
|
* @param parent
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private int countChildElements(Element parent) {
|
||||||
|
int numElements = 0;
|
||||||
|
NodeList childNodes = parent.getChildNodes();
|
||||||
|
for (int k = 0 ; k < childNodes.getLength() ; k++)
|
||||||
|
if (childNodes.item(k).getNodeType() == Node.ELEMENT_NODE)
|
||||||
|
numElements ++;
|
||||||
|
return numElements;
|
||||||
|
}
|
||||||
|
|
||||||
public void testDeadlockDuringProjectCreation() throws Exception {
|
public void testDeadlockDuringProjectCreation() throws Exception {
|
||||||
for (int i=0; i < 10; ++i) {
|
for (int i=0; i < 10; ++i) {
|
||||||
oneTimeTearDown();
|
oneTimeTearDown();
|
||||||
oneTimeSetUp();
|
oneTimeSetUp();
|
||||||
Thread t= new Thread() {
|
Thread t= new Thread() {
|
||||||
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
ICDescriptor desc = CCorePlugin.getDefault().getCProjectDescription(fProject, true);
|
ICDescriptor desc = CCorePlugin.getDefault().getCProjectDescription(fProject, true);
|
||||||
|
|
Loading…
Add table
Reference in a new issue