CppEditor: Use a timeout in waitForRehighlightedSemanticDocument()

As in all the other wait() functions.
This makes sure we never hang indefinitely in tests.

Change-Id: I119cc0d6d6146f193ffde37207a94f61b3c70d87
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
Christian Kandeler
2024-07-10 14:02:52 +02:00
parent e451f42fc7
commit 978042b582
7 changed files with 16 additions and 8 deletions

View File

@@ -488,7 +488,7 @@ void DoxygenTest::runTest(const QByteArray &original,
// testDocument.m_editorWidget->unfoldAll();
testDocument.m_editor->setCursorPosition(testDocument.m_cursorPosition);
TestCase::waitForRehighlightedSemanticDocument(testDocument.m_editorWidget);
QVERIFY(TestCase::waitForRehighlightedSemanticDocument(testDocument.m_editorWidget));
// Send 'ENTER' key press
QKeyEvent event(QEvent::KeyPress, Qt::Key_Enter, Qt::NoModifier);

View File

@@ -295,10 +295,18 @@ bool TestCase::waitForProcessedEditorDocument(const FilePath &filePath, int time
return waitForProcessedEditorDocument_internal(editorDocument, timeOutInMs);
}
CPlusPlus::Document::Ptr TestCase::waitForRehighlightedSemanticDocument(CppEditorWidget *editorWidget)
CPlusPlus::Document::Ptr TestCase::waitForRehighlightedSemanticDocument(
CppEditorWidget *editorWidget, int timeoutInMs)
{
while (!editorWidget->isSemanticInfoValid())
QElapsedTimer timer;
timer.start();
while (!editorWidget->isSemanticInfoValid()) {
if (timer.elapsed() >= timeoutInMs)
return {};
QCoreApplication::processEvents();
QThread::msleep(20);
}
return editorWidget->semanticInfo().doc;
}

View File

@@ -140,7 +140,7 @@ public:
const Utils::FilePath &filePath, int timeOutInMs = 5000);
static CPlusPlus::Document::Ptr waitForRehighlightedSemanticDocument(
CppEditorWidget *editorWidget);
CppEditorWidget *editorWidget, int timeoutInMs = defaultTimeOutInMs);
enum { defaultTimeOutInMs = 30 * 1000 /*= 30 secs*/ };
static bool waitUntilProjectIsFullyOpened(ProjectExplorer::Project *project,

View File

@@ -77,7 +77,7 @@ UseSelectionsTestCase::UseSelectionsTestCase(CppTestDocument &testFile,
closeEditorAtEndOfTestCase(testFile.m_editor);
testFile.m_editor->setCursorPosition(testFile.m_cursorPosition);
waitForRehighlightedSemanticDocument(m_editorWidget);
QVERIFY(waitForRehighlightedSemanticDocument(m_editorWidget));
bool hasTimedOut;
const SelectionList selections = waitForUseSelections(&hasTimedOut);

View File

@@ -164,7 +164,7 @@ TestActionsTestCase::TestActionsTestCase(const Actions &tokenActions, const Acti
QVERIFY(CppModelManager::workingCopy().get(filePath));
// Rehighlight
waitForRehighlightedSemanticDocument(editorWidget);
QVERIFY(waitForRehighlightedSemanticDocument(editorWidget));
// Run all file actions
executeActionsOnEditorWidget(editorWidget, fileActions);

View File

@@ -310,7 +310,7 @@ F2TestCase::F2TestCase(CppEditorAction action,
// Rehighlight
if (!useClangd)
waitForRehighlightedSemanticDocument(testFile->m_editorWidget);
QVERIFY(waitForRehighlightedSemanticDocument(testFile->m_editorWidget));
}
// Activate editor of initial test file

View File

@@ -104,7 +104,7 @@ BaseQuickFixTestCase::BaseQuickFixTestCase(const QList<TestDocumentPtr> &testDoc
}
// Rehighlight
waitForRehighlightedSemanticDocument(document->m_editorWidget);
QVERIFY(waitForRehighlightedSemanticDocument(document->m_editorWidget));
}
// Enforce the default cpp code style, so we are independent of config file settings.