From ab1a5f10039429e9114cd905716b31bbec601d60 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Tue, 27 Oct 2015 12:02:54 +0100 Subject: [PATCH] Fix pauseEvents() test to test what should be true, not what is. If the future is finished when a watcher starts watching it, it is perfectly reasonable for the watcher to get the finished message promptly. If you pause the watcher before any message loops get to run, the message presently won't get through until the watcher is resumed, but there is no reason to guarantee that; indeed, one could consider it somewhat perverse behavior. So move the reportFinished() calls to after the pause()s. Also eliminate a used-once local variable and use QTRY_VERIFY() in one place where qWait() was used before. Change-Id: I4bc6091fd7437a4d341be511b7a140f3d72d850e Reviewed-by: Marc Mutz --- .../qfuturewatcher/tst_qfuturewatcher.cpp | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/tests/auto/corelib/thread/qfuturewatcher/tst_qfuturewatcher.cpp b/tests/auto/corelib/thread/qfuturewatcher/tst_qfuturewatcher.cpp index f64d92dcdb..c4fad93e4b 100644 --- a/tests/auto/corelib/thread/qfuturewatcher/tst_qfuturewatcher.cpp +++ b/tests/auto/corelib/thread/qfuturewatcher/tst_qfuturewatcher.cpp @@ -677,11 +677,6 @@ void tst_QFutureWatcher::pauseEvents() QFutureInterface iface; iface.reportStarted(); - QFuture a = iface.future(); - - int value = 0; - iface.reportFinished(&value); - QFutureWatcher watcher; SignalSlotObject object; @@ -689,14 +684,17 @@ void tst_QFutureWatcher::pauseEvents() QSignalSpy resultReadySpy(&watcher, &QFutureWatcher::resultReadyAt); QVERIFY(resultReadySpy.isValid()); - watcher.setFuture(a); + watcher.setFuture(iface.future()); watcher.pause(); + int value = 0; + iface.reportFinished(&value); + QTest::qWait(10); QCOMPARE(resultReadySpy.count(), 0); watcher.resume(); - QTest::qWait(10); + QTRY_VERIFY2(!resultReadySpy.isEmpty(), "Result didn't arrive"); QCOMPARE(resultReadySpy.count(), 1); } { @@ -705,9 +703,6 @@ void tst_QFutureWatcher::pauseEvents() QFuture a = iface.future(); - int value = 0; - iface.reportFinished(&value); - QFutureWatcher watcher; SignalSlotObject object; @@ -718,6 +713,9 @@ void tst_QFutureWatcher::pauseEvents() watcher.setFuture(a); a.pause(); + int value = 0; + iface.reportFinished(&value); + QFuture b; watcher.setFuture(b); // If we watch b instead, resuming a a.resume(); // should give us no results.