diff options
author | Nikolai Kosjar <nikolai.kosjar@theqtcompany.com> | 2015-07-10 10:39:05 +0200 |
---|---|---|
committer | Nikolai Kosjar <nikolai.kosjar@theqtcompany.com> | 2015-07-10 09:30:01 +0000 |
commit | 7f4ce089d32d942466a1e101459f8bac0efea3d9 (patch) | |
tree | a9df393555cd1e700d5690f2181b50ec68bf85ce /src | |
parent | 6682df070999240e861d3aa8642b731a1be2a496 (diff) | |
download | qt-creator-7f4ce089d32d942466a1e101459f8bac0efea3d9.tar.gz |
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>
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/clangcodemodel/test/clangcodecompletion_test.cpp | 63 |
1 files changed, 58 insertions, 5 deletions
diff --git a/src/plugins/clangcodemodel/test/clangcodecompletion_test.cpp b/src/plugins/clangcodemodel/test/clangcodecompletion_test.cpp index 2ddcf8bcb9..95c43eeb20 100644 --- a/src/plugins/clangcodemodel/test/clangcodecompletion_test.cpp +++ b/src/plugins/clangcodemodel/test/clangcodecompletion_test.cpp @@ -658,6 +658,59 @@ bool MonitorGeneratedUiFile::waitUntilGenerated(int timeout) const 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 namespace ClangCodeModel { @@ -909,11 +962,11 @@ void ClangCodeCompletionTest::testUnsavedFilesTrackingByModifyingIncludedFileExt ProposalModel proposal = completionResults(openSource.editor()); QVERIFY(hasItem(proposal, "globalFromHeader")); - // Simulate external modification - QThread::sleep(1); // Ensures different time stamp and thus that the difference will be noticed - QVERIFY(writeFile(headerDocument.filePath, "int globalFromHeaderReloaded;\n")); - QSignalSpy waitForReloadedDocument(openHeader.editor()->document(), - SIGNAL(reloadFinished(bool))); + // Simulate external modification and wait for reload + WriteFileAndWaitForReloadedDocument waitForReloadedDocument( + headerDocument.filePath, + "int globalFromHeaderReloaded;\n", + openHeader.editor()->document()); QVERIFY(waitForReloadedDocument.wait()); // Retrigger completion and check if its updated |