Fix unstable test due to a race in QThread

QThread::finished() is emitted before setting the thread's state to
finished and !running, which means it's possible to receive the
finished() signal and act on it while QThread::isRunning() still
returns true.

This test randomly fails due to this race. Fix it by using checking
the return value of QThread::wait() instead.

Change-Id: Ibf347fc9a2e8d32b328227ee6978e1129dd781f4
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Bradley T. Hughes 2011-11-03 11:10:44 +01:00 committed by Qt by Nokia
parent ec5e59b73c
commit faa6113c41

View File

@ -392,7 +392,7 @@ void tst_QDBusPendingCall::watcher_waitForFinished_threaded()
QTestEventLoop::instance().connect(&thread, SIGNAL(finished()), SLOT(exitLoop()));
thread.start();
QTestEventLoop::instance().enterLoop(10);
QVERIFY(!thread.isRunning());
QVERIFY(thread.wait(3000));
QVERIFY(!QTestEventLoop::instance().timeout());
}