diff options
author | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2024-01-31 15:23:17 +0100 |
---|---|---|
committer | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2024-01-31 21:18:48 +0100 |
commit | 72f5b35b3d7704db6ef16e4c60751ed8444363be (patch) | |
tree | bad01b21880dbcd7d9dcbe4e7387916bde9e0379 | |
parent | 62bea90207b6fde116ef6fbb926565b648708d57 (diff) |
Stabilize tst_QFileSystemModel::showFilesOnly test case
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.7 6.6 6.5
Change-Id: Ic98bb53c696441131bbc1055b64822faf2aec96f
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
-rw-r--r-- | tests/auto/gui/itemmodels/qfilesystemmodel/BLACKLIST | 2 | ||||
-rw-r--r-- | tests/auto/gui/itemmodels/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 a9b2dfb736..4119afce84 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 483be7c7e4..e1d55af885 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() |