1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-22 22:22:11 +02:00

another attempt to fix race condition in Qt tests

after tests were fixed found funny bug that was there forever test was
creating incorrect header file because our comment extractor takes
comment from first occurence of function name, it is not actual java
parser. Because indexer was not running test was passing.

Change-Id: Ib0cea722e6c9766949d07b629ef7a9197529ef45
Signed-off-by: Alena Laskavaia <elaskavaia.cdt@gmail.com>
Reviewed-on: https://git.eclipse.org/r/37410
Tested-by: Hudson CI
This commit is contained in:
Alena Laskavaia 2014-12-01 11:21:03 -05:00 committed by Elena Laskavaia
parent 351f1b86a4
commit 1e517e23e4
3 changed files with 38 additions and 15 deletions

View file

@ -7,6 +7,7 @@
*/
package org.eclipse.cdt.qt.tests;
import org.eclipse.cdt.core.CCProjectNature;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.IPDOMManager;
import org.eclipse.cdt.core.index.IIndex;
@ -18,6 +19,11 @@ import org.eclipse.cdt.core.testplugin.util.TestSourceReader;
import org.eclipse.cdt.qt.core.QtNature;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceRunnable;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
public class BaseQtTestCase extends BaseTestCase {
@ -39,15 +45,31 @@ public class BaseQtTestCase extends BaseTestCase {
protected ICProject fCProject;
protected IIndex fIndex;
public static ICProject createQtProject(final String projectName, final String binFolderName) throws CoreException {
final IWorkspace ws = ResourcesPlugin.getWorkspace();
final ICProject newProject[] = new ICProject[1];
ws.run(new IWorkspaceRunnable() {
@Override
public void run(IProgressMonitor monitor) throws CoreException {
ICProject cproject = CProjectHelper.createCProject(projectName, binFolderName, IPDOMManager.ID_FAST_INDEXER);
if (!cproject.getProject().hasNature(CCProjectNature.CC_NATURE_ID)) {
CProjectHelper.addNatureToProject(cproject.getProject(), CCProjectNature.CC_NATURE_ID, null);
QtNature.addNature(cproject.getProject(), new NullProgressMonitor());
}
newProject[0] = cproject;
}
}, null);
return newProject[0];
}
@Override
protected void setUp() throws Exception {
super.setUp();
String projectName = "__" + getClass().getSimpleName() + "__";
fCProject = CProjectHelper.createCCProject(projectName, "bin", IPDOMManager.ID_FAST_INDEXER);
fCProject = createQtProject(projectName, "bin");
fProject = fCProject.getProject();
QtNature.addNature(fProject, new NullProgressMonitor());
fIndex = CCorePlugin.getIndexManager().getIndex(fCProject);
indexQObject_h();
@ -150,15 +172,17 @@ public class BaseQtTestCase extends BaseTestCase {
// add the new content
fFile = TestSourceReader.createFile(fProject, filename, contents[0]);
CCorePlugin.getIndexManager().reindex(fCProject);// just make sure we re-indexing here
// wait for the index to change
Thread.yield();
waitForIndexer(fCProject);
for(long stopAt = System.currentTimeMillis() + 3000;
System.currentTimeMillis() < stopAt && timestamp == indexManager.getIndex(fCProject).getLastWriteAccess();
Thread.sleep(100)) {
/* intentionally empty*/
waitForIndexer(fCProject);
}
assertNotSame(timestamp, indexManager.getIndex(fCProject).getLastWriteAccess());
}
/**

View file

@ -100,7 +100,6 @@ public class QmlRegistrationTests extends BaseQtTestCase {
// }
public void testQmlRegisterFwdDecl() throws Exception {
loadComment("qmlregistertype.hh");
waitForIndexer(fCProject);
QtIndex qtIndex = QtIndex.getIndex(fProject);
assertNotNull(qtIndex);

View file

@ -14,6 +14,16 @@ public class QtIndexTests extends BaseQtTestCase {
private static final String Filename_testCache = "testCache.hh";
// #include "junit-QObject.hh"
// class B : public QObject
// {
// Q_OBJECT
// Q_PROPERTY(bool allowed READ isAllowed)
// };
public void changeBDecl() throws Exception {
loadComment(Filename_testCache);
}
// #include "junit-QObject.hh"
// class B : public QObject
// {
@ -36,14 +46,4 @@ public class QtIndexTests extends BaseQtTestCase {
assertNotNull(qobj2);
assertEquals("B", qobj2.getName());
}
// #include "junit-QObject.hh"
// class B : public QObject
// {
// Q_OBJECT
// Q_PROPERTY(bool allowed READ isAllowed())
// };
public void changeBDecl() throws Exception {
loadComment(Filename_testCache);
}
}