I noticed unexpected unit test failures when running the tests with
Valgrind. The reason was that test execution was slowed down a lot,
such that that TestBase::waitForFinishedPathLoading() did not receive
the view's signal within the default timeout of 2 seconds, and that
this failure was not detected in every test -> the tests failed later
on because not all expected items had been loaded yet.
To fix this, I changed two things:
1. Added an assert in TestBase::waitForFinishedPathLoading() that checks
if the signal has been received. Continuing does not make much sense if
that is not the case.
2. Increased the default timeout to 20 seconds. The reason why there is
a finite timeout at all is that I didn't want to waste too much time on
machines where the file kioslave seems to have problems loading a
directory (I've seen corresponding test logs at cdash.org). However, with
the first change I mentioned above, the waiting time is lost only once
(due to the assert) rather than every time a directory is loaded
-> I think that the timeout increase does not lead to an increased waste
of time on such machines.
// while we were waiting in QTest::qWaitForWindowShown(view)
// -> waitForFinishedPathLoading(view) would fail in that case.
if (spyFinishedPathLoading.isEmpty()) {
// while we were waiting in QTest::qWaitForWindowShown(view)
// -> waitForFinishedPathLoading(view) would fail in that case.
if (spyFinishedPathLoading.isEmpty()) {
- Q_ASSERT(waitForFinishedPathLoading(view));
+ waitForFinishedPathLoading(view);
// Before we proceed, we have to make sure that the view has finished
// loading the contents of the expanded folder.
// Before we proceed, we have to make sure that the view has finished
// loading the contents of the expanded folder.
- QVERIFY(waitForFinishedPathLoading(&view));
+ waitForFinishedPathLoading(&view);
}
// Collapse URLs one by one and verify the result of DolphinDetailsView::expandedUrls()
}
// Collapse URLs one by one and verify the result of DolphinDetailsView::expandedUrls()
// Show hidden files. This triggers the dir lister
// -> we have to wait until loading the hidden files is finished
view.setShowHiddenFiles(true);
// Show hidden files. This triggers the dir lister
// -> we have to wait until loading the hidden files is finished
view.setShowHiddenFiles(true);
- QVERIFY(waitForFinishedPathLoading(&view));
+ waitForFinishedPathLoading(&view);
QVERIFY(view.showHiddenFiles());
QCOMPARE(viewItems(&view), QStringList() << ".f" << "a" << "b" << "c" << "d" << "e");
QVERIFY(view.showHiddenFiles());
QCOMPARE(viewItems(&view), QStringList() << ".f" << "a" << "b" << "c" << "d" << "e");
// Change the URL
view.setUrl(dir.name() + "51");
// Change the URL
view.setUrl(dir.name() + "51");
- QVERIFY(waitForFinishedPathLoading(&view));
+ waitForFinishedPathLoading(&view);
qApp->sendPostedEvents();
// Go back, but do not call DolphinView::restoreState()
view.setUrl(dir.url());
qApp->sendPostedEvents();
// Go back, but do not call DolphinView::restoreState()
view.setUrl(dir.url());
- QVERIFY(waitForFinishedPathLoading(&view));
+ waitForFinishedPathLoading(&view);
qApp->sendPostedEvents();
// Verify that the view is scrolled to top-left corner and that item 45 is not the current item.
qApp->sendPostedEvents();
// Verify that the view is scrolled to top-left corner and that item 45 is not the current item.
// Change the URL again
view.setUrl(dir.name() + "51");
// Change the URL again
view.setUrl(dir.name() + "51");
- QVERIFY(waitForFinishedPathLoading(&view));
+ waitForFinishedPathLoading(&view);
qApp->sendPostedEvents();
// Check that the current item and scroll position are correct if DolphinView::restoreState()
qApp->sendPostedEvents();
// Check that the current item and scroll position are correct if DolphinView::restoreState()
view.setUrl(dir.url());
QDataStream restoreStream(viewState);
view.restoreState(restoreStream);
view.setUrl(dir.url());
QDataStream restoreStream(viewState);
view.restoreState(restoreStream);
- QVERIFY(waitForFinishedPathLoading(&view));
+ waitForFinishedPathLoading(&view);
qApp->sendPostedEvents();
QCOMPARE(itemView(&view)->currentIndex(), index45);
qApp->sendPostedEvents();
QCOMPARE(itemView(&view)->currentIndex(), index45);
qApp->sendPostedEvents();
if (!spy.isEmpty()) {
// The dir lister reloads the directory. We wait until the loading is finished.
qApp->sendPostedEvents();
if (!spy.isEmpty()) {
// The dir lister reloads the directory. We wait until the loading is finished.
- QVERIFY(waitForFinishedPathLoading(&view));
+ waitForFinishedPathLoading(&view);
}
// Current item and scroll position should not change.
}
// Current item and scroll position should not change.
// while we were waiting in QTest::qWaitForWindowShown(view)
// -> waitForFinishedPathLoading(view) would fail in that case.
if (spyFinishedPathLoading.isEmpty()) {
// while we were waiting in QTest::qWaitForWindowShown(view)
// -> waitForFinishedPathLoading(view) would fail in that case.
if (spyFinishedPathLoading.isEmpty()) {
- Q_ASSERT(waitForFinishedPathLoading(view));
+ waitForFinishedPathLoading(view);
return view->m_viewAccessor.itemView();
}
return view->m_viewAccessor.itemView();
}
-bool TestBase::waitForFinishedPathLoading(DolphinView* view, int milliseconds)
+void TestBase::waitForFinishedPathLoading(DolphinView* view, int milliseconds)
- return QTest::kWaitForSignal(view, SIGNAL(finishedPathLoading(const KUrl&)), milliseconds);
+ // If the signal is not received, somthing is going seriously wrong.
+ // -> assert here rather than continuing, which might result in test failures which are hard to unterstand.
+ bool viewHasFinishedLoading = QTest::kWaitForSignal(view, SIGNAL(finishedPathLoading(const KUrl&)), milliseconds);
+ Q_ASSERT(viewHasFinishedLoading);
+ Q_UNUSED(viewHasFinishedLoading) // suppress compiler warining is asserts are disabled
}
void TestBase::reloadViewAndWait(DolphinView* view)
{
view->reload();
}
void TestBase::reloadViewAndWait(DolphinView* view)
{
view->reload();
- QVERIFY(waitForFinishedPathLoading(view));
+ waitForFinishedPathLoading(view);
}
QStringList TestBase::viewItems(const DolphinView* view)
}
QStringList TestBase::viewItems(const DolphinView* view)
/**
* Waits until the view emits its finishedPathLoading(const KUrl&) signal.
/**
* Waits until the view emits its finishedPathLoading(const KUrl&) signal.
- * Returns false if it is not received within the given number of milliseconds.
+ * Asserts if the signal is not received within the given number of milliseconds.
- static bool waitForFinishedPathLoading(DolphinView* view, int milliseconds=2000);
+ static void waitForFinishedPathLoading(DolphinView* view, int milliseconds=20000);
/** Reloads the view and waits for the finishedPathLoading(const KUrl&) signal. */
static void reloadViewAndWait(DolphinView* view);
/** Reloads the view and waits for the finishedPathLoading(const KUrl&) signal. */
static void reloadViewAndWait(DolphinView* view);