From e20f2a6c8b0f0cf8ddbdec6771f1cfcad141eb1a Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Wed, 31 Jan 2024 15:23:17 +0100 Subject: [PATCH] Stabilize tst_QFileSystemModel::showFilesOnly test case MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Amends 83e5d74864a8780445db4b34e406afc53b331039. A model index returned by QFileSystemModel might become invalid when events get processed, so don't store the result of setRootPath to re-use it in a QTRY_COMPARE function. Instead, always ask for a fresh model index. Also, use std::chrono::duration::count correctly; it returns the "tick", not the corresponding milliseconds, so (10s).count() returns 10 instead of 10000. Explicitly use 10000ms here. Un-blacklist the test on macOS again. Task-number: QTBUG-74471 Pick-to: 6.6 6.5 Change-Id: Ic98bb53c696441131bbc1055b64822faf2aec96f Reviewed-by: Tor Arne Vestbø Reviewed-by: Eskil Abrahamsen Blomfeldt Reviewed-by: Marc Mutz (cherry picked from commit 72f5b35b3d7704db6ef16e4c60751ed8444363be) Reviewed-by: Qt Cherry-pick Bot --- .../auto/gui/itemmodels/qfilesystemmodel/BLACKLIST | 2 -- .../qfilesystemmodel/tst_qfilesystemmodel.cpp | 13 ++++++++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/tests/auto/gui/itemmodels/qfilesystemmodel/BLACKLIST b/tests/auto/gui/itemmodels/qfilesystemmodel/BLACKLIST index a9b2dfb7363..4119afce84d 100644 --- a/tests/auto/gui/itemmodels/qfilesystemmodel/BLACKLIST +++ b/tests/auto/gui/itemmodels/qfilesystemmodel/BLACKLIST @@ -3,5 +3,3 @@ ubuntu b2qt [specialFiles] b2qt -[showFilesOnly] -macos diff --git a/tests/auto/gui/itemmodels/qfilesystemmodel/tst_qfilesystemmodel.cpp b/tests/auto/gui/itemmodels/qfilesystemmodel/tst_qfilesystemmodel.cpp index 483be7c7e49..e1d55af885d 100644 --- a/tests/auto/gui/itemmodels/qfilesystemmodel/tst_qfilesystemmodel.cpp +++ b/tests/auto/gui/itemmodels/qfilesystemmodel/tst_qfilesystemmodel.cpp @@ -689,14 +689,17 @@ void tst_QFileSystemModel::showFilesOnly() const auto subdir = u"sub_directory"_s; QVERIFY(createFiles(&model, tmp, files, 0, {subdir})); + // The model changes asynchronously when we run the event loop in the QTRY_... + // macros, so the root index returned by an earlier call to setRootPath might + // become invalid. Make sure we use a fresh one for each iteration. + // QTBUG-74471 // WHAT: setting the root path of the model to a dir with some files and a subdir - QModelIndex root = model.setRootPath(tmp); - QTRY_COMPARE(model.rowCount(root), files.size() + 1); + QTRY_COMPARE(model.rowCount(model.setRootPath(tmp)), files.size() + 1); // Change the model to only show files model.setFilter(QDir::Files); - QTRY_COMPARE(model.rowCount(root), files.size()); + QTRY_COMPARE(model.rowCount(model.setRootPath(tmp)), files.size()); // WHEN: setting the root path to a subdir QModelIndex subIndex = model.setRootPath(tmp + u'/' + subdir); @@ -704,9 +707,9 @@ void tst_QFileSystemModel::showFilesOnly() // THEN: setting the root path to the previous (parent) dir, the model should // still only show files. - root = model.setRootPath(tmp); // Doubling the default timeout (5s) as this test to fails on macos on the CI - QTRY_COMPARE_WITH_TIMEOUT(model.rowCount(root), files.size(), (10s).count()); + QTRY_COMPARE_WITH_TIMEOUT(model.rowCount(model.setRootPath(tmp)), files.size(), + (10000ms).count()); } void tst_QFileSystemModel::nameFilters()