CppTools: Tests: time out in waitForFileInGlobalSnapshot()

Change-Id: I0bf7d826d53749c5fd1be1e4f3c2faa403d13342
Reviewed-by: Christian Stenger <christian.stenger@theqtcompany.com>
This commit is contained in:
Nikolai Kosjar
2015-02-17 15:05:22 +01:00
parent 1e0b7e527f
commit 93c8509a50
5 changed files with 25 additions and 13 deletions

View File

@@ -88,8 +88,7 @@ public:
m_textDocument = m_editorWidget->document();
// Get Document
waitForFileInGlobalSnapshot(fileName);
const Document::Ptr document = globalSnapshot().document(fileName);
const Document::Ptr document = waitForFileInGlobalSnapshot(fileName);
QVERIFY(document);
QVERIFY(document->diagnosticMessages().isEmpty());

View File

@@ -128,7 +128,7 @@ private:
m_editor = EditorManager::openEditor(m_fileName);
QVERIFY(m_editor);
waitForFileInGlobalSnapshot(m_fileName);
QVERIFY(waitForFileInGlobalSnapshot(m_fileName));
}
void doAfterLocatorRun()

View File

@@ -170,14 +170,19 @@ bool TestCase::closeEditorWithoutGarbageCollectorInvocation(Core::IEditor *edito
return closeEditorsWithoutGarbageCollectorInvocation(QList<Core::IEditor *>() << editor);
}
CPlusPlus::Document::Ptr TestCase::waitForFileInGlobalSnapshot(const QString &filePath)
CPlusPlus::Document::Ptr TestCase::waitForFileInGlobalSnapshot(const QString &filePath,
int timeOutInMs)
{
return waitForFilesInGlobalSnapshot(QStringList(filePath)).first();
const auto documents = waitForFilesInGlobalSnapshot(QStringList(filePath), timeOutInMs);
return documents.isEmpty() ? CPlusPlus::Document::Ptr() : documents.first();
}
QList<CPlusPlus::Document::Ptr> TestCase::waitForFilesInGlobalSnapshot(
const QStringList &filePaths)
QList<CPlusPlus::Document::Ptr> TestCase::waitForFilesInGlobalSnapshot(const QStringList &filePaths,
int timeOutInMs)
{
QTime t;
t.start();
QList<CPlusPlus::Document::Ptr> result;
foreach (const QString &filePath, filePaths) {
forever {
@@ -185,13 +190,15 @@ QList<CPlusPlus::Document::Ptr> TestCase::waitForFilesInGlobalSnapshot(
result.append(document);
break;
}
if (t.elapsed() > timeOutInMs)
return QList<CPlusPlus::Document::Ptr>();
QCoreApplication::processEvents();
}
}
return result;
}
bool TestCase::waitUntilCppModelManagerIsAwareOf(Project *project, int timeOut)
bool TestCase::waitUntilCppModelManagerIsAwareOf(Project *project, int timeOutInMs)
{
if (!project)
return false;
@@ -203,7 +210,7 @@ bool TestCase::waitUntilCppModelManagerIsAwareOf(Project *project, int timeOut)
forever {
if (modelManager->projectInfo(project).isValid())
return true;
if (t.elapsed() > timeOut)
if (t.elapsed() > timeOutInMs)
return false;
QCoreApplication::processEvents();
}

View File

@@ -93,11 +93,16 @@ public:
static CPlusPlus::Snapshot globalSnapshot();
static bool garbageCollectGlobalSnapshot();
static bool waitUntilCppModelManagerIsAwareOf(ProjectExplorer::Project *project,
int timeOut = 30 * 1000 /*= 30 secs*/);
static CPlusPlus::Document::Ptr waitForFileInGlobalSnapshot(const QString &filePath);
enum { defaultTimeOutInMs = 30 * 1000 /*= 30 secs*/ };
static bool waitUntilCppModelManagerIsAwareOf(
ProjectExplorer::Project *project,
int timeOutInMs = defaultTimeOutInMs);
static CPlusPlus::Document::Ptr waitForFileInGlobalSnapshot(
const QString &filePath,
int timeOutInMs = defaultTimeOutInMs);
static QList<CPlusPlus::Document::Ptr> waitForFilesInGlobalSnapshot(
const QStringList &filePaths);
const QStringList &filePaths,
int timeOutInMs = defaultTimeOutInMs);
static bool writeFile(const QString &filePath, const QByteArray &contents);