From d609b20842c0493b13a24653ad0064d6f98d957b Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Wed, 13 Jul 2022 17:26:43 +0200 Subject: [PATCH] QCompleter: make filesystem test robust against slow I/O MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use a signal spy to watch for the relevant signal from the file system model and wait for that before checking whether the completer responded to that signal by showing (or not showing) the popup. If the file system model doesn't fire within the default timeout of 5 seconds, skip the rest of the test. Fixes: QTBUG-46113 Pick-to: 6.4 6.3 6.2 Change-Id: I9becfe19a220bdb178ed8275c327d55ea19aa342 Reviewed-by: Axel Spoerl Reviewed-by: Tor Arne Vestbø --- tests/auto/widgets/util/qcompleter/tst_qcompleter.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/auto/widgets/util/qcompleter/tst_qcompleter.cpp b/tests/auto/widgets/util/qcompleter/tst_qcompleter.cpp index 897608bca83..76b12d7aead 100644 --- a/tests/auto/widgets/util/qcompleter/tst_qcompleter.cpp +++ b/tests/auto/widgets/util/qcompleter/tst_qcompleter.cpp @@ -1636,6 +1636,7 @@ void tst_QCompleter::QTBUG_14292_filesystem() // to pop up the completion list due to file changed signals. FileSystem fs; QFileSystemModel model; + QSignalSpy filesAddedSpy(&model, &QAbstractItemModel::rowsInserted); model.setRootPath(fs.path()); QVERIFY(fs.createDirectory(QLatin1String(testDir1))); @@ -1672,13 +1673,16 @@ void tst_QCompleter::QTBUG_14292_filesystem() QTest::keyClick(&edit, 'r'); QTRY_VERIFY(!comp.popup()->isVisible()); QVERIFY(fs.createDirectory(QStringLiteral("hero"))); + if (!filesAddedSpy.wait()) + QSKIP("File system model didn't notify about new directory, skipping tests"); QTRY_VERIFY(comp.popup()->isVisible()); QCOMPARE(comp.popup()->model()->rowCount(), 1); QTest::keyClick(comp.popup(), Qt::Key_Escape); QTRY_VERIFY(!comp.popup()->isVisible()); QVERIFY(fs.createDirectory(QStringLiteral("nothingThere"))); //there is no reason creating a file should open a popup, it did in Qt 4.7.0 - QTest::qWait(60); + if (!filesAddedSpy.wait()) + QSKIP("File system model didn't notify about new file, skipping tests"); QVERIFY(!comp.popup()->isVisible()); QTest::keyClick(&edit, Qt::Key_Backspace); @@ -1696,7 +1700,8 @@ void tst_QCompleter::QTBUG_14292_filesystem() QVERIFY(fs.createDirectory(QStringLiteral("hemo"))); //there is no reason creating a file should open a popup, it did in Qt 4.7.0 - QTest::qWait(60); + if (!filesAddedSpy.wait()) + QSKIP("File system model didn't notify about new file, skipping tests"); QVERIFY(!comp.popup()->isVisible()); }