forked from qt-creator/qt-creator
Clang: Tests: Make waiting for reloaded document more robust
testUnsavedFilesTrackingByModifyingIncludedFileExternally() is flaky. Apparently the hard coded timeout is not enough for all circumstances. Change-Id: I9f884e488d3c4bd5398e505ecee122912d946e6b Reviewed-by: Christian Stenger <christian.stenger@theqtcompany.com>
This commit is contained in:
@@ -658,6 +658,59 @@ bool MonitorGeneratedUiFile::waitUntilGenerated(int timeout) const
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class WriteFileAndWaitForReloadedDocument : public QObject
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
WriteFileAndWaitForReloadedDocument(const QString &filePath,
|
||||||
|
const QByteArray &fileContents,
|
||||||
|
Core::IDocument *document)
|
||||||
|
: m_filePath(filePath)
|
||||||
|
, m_fileContents(fileContents)
|
||||||
|
{
|
||||||
|
QTC_CHECK(document);
|
||||||
|
connect(document, &Core::IDocument::reloadFinished,
|
||||||
|
this, &WriteFileAndWaitForReloadedDocument::onReloadFinished);
|
||||||
|
}
|
||||||
|
|
||||||
|
void onReloadFinished()
|
||||||
|
{
|
||||||
|
m_onReloadFinished = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wait() const
|
||||||
|
{
|
||||||
|
QTC_ASSERT(writeFile(m_filePath, m_fileContents), return false);
|
||||||
|
|
||||||
|
QTime totalTime;
|
||||||
|
totalTime.start();
|
||||||
|
|
||||||
|
QTime writeFileAgainTime;
|
||||||
|
writeFileAgainTime.start();
|
||||||
|
|
||||||
|
forever {
|
||||||
|
if (m_onReloadFinished)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if (totalTime.elapsed() > 10000)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (writeFileAgainTime.elapsed() > 1000) {
|
||||||
|
// The timestamp did not change, try again now.
|
||||||
|
QTC_ASSERT(writeFile(m_filePath, m_fileContents), return false);
|
||||||
|
writeFileAgainTime.restart();
|
||||||
|
}
|
||||||
|
|
||||||
|
QCoreApplication::processEvents();
|
||||||
|
QThread::msleep(20);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool m_onReloadFinished = false;
|
||||||
|
QString m_filePath;
|
||||||
|
QByteArray m_fileContents;
|
||||||
|
};
|
||||||
|
|
||||||
} // anonymous namespace
|
} // anonymous namespace
|
||||||
|
|
||||||
namespace ClangCodeModel {
|
namespace ClangCodeModel {
|
||||||
@@ -909,11 +962,11 @@ void ClangCodeCompletionTest::testUnsavedFilesTrackingByModifyingIncludedFileExt
|
|||||||
ProposalModel proposal = completionResults(openSource.editor());
|
ProposalModel proposal = completionResults(openSource.editor());
|
||||||
QVERIFY(hasItem(proposal, "globalFromHeader"));
|
QVERIFY(hasItem(proposal, "globalFromHeader"));
|
||||||
|
|
||||||
// Simulate external modification
|
// Simulate external modification and wait for reload
|
||||||
QThread::sleep(1); // Ensures different time stamp and thus that the difference will be noticed
|
WriteFileAndWaitForReloadedDocument waitForReloadedDocument(
|
||||||
QVERIFY(writeFile(headerDocument.filePath, "int globalFromHeaderReloaded;\n"));
|
headerDocument.filePath,
|
||||||
QSignalSpy waitForReloadedDocument(openHeader.editor()->document(),
|
"int globalFromHeaderReloaded;\n",
|
||||||
SIGNAL(reloadFinished(bool)));
|
openHeader.editor()->document());
|
||||||
QVERIFY(waitForReloadedDocument.wait());
|
QVERIFY(waitForReloadedDocument.wait());
|
||||||
|
|
||||||
// Retrigger completion and check if its updated
|
// Retrigger completion and check if its updated
|
||||||
|
Reference in New Issue
Block a user