Don't assume processEvents(WaitForMoreEvents) will process timers

The WaitForMoreEvents flag only guarantees that we will process _some_
events -- either if they are in the event queue already, or by sleeping
and then waking up to process an event. This event might be a system
event, not the timer firing, so a single call to processEvents() is
not enough to guarantee that the timer has fired. Instead we do a
Q_COMPARE with a timeout, where we continiously process events until
we see that the timer fired.

Change-Id: I5dc04377f04190f3505be22e877af73d11b7547d
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Tor Arne Vestbø 2013-08-27 12:06:17 +02:00 committed by The Qt Project
parent 78f3f35a8b
commit eb614cf7e7

View File

@ -148,8 +148,7 @@ void tst_QEventDispatcher::registerTimer()
// process events, waiting for the next event... this should only fire the precise timer
receivedEventType = -1;
timerIdFromEvent = -1;
QVERIFY(eventDispatcher->processEvents(QEventLoop::WaitForMoreEvents));
QCOMPARE(receivedEventType, int(QEvent::Timer));
QTRY_COMPARE_WITH_TIMEOUT(receivedEventType, int(QEvent::Timer), PreciseTimerInterval * 2);
QCOMPARE(timerIdFromEvent, preciseTimerId);
// now unregister it and make sure it's gone
eventDispatcher->unregisterTimer(preciseTimerId);
@ -161,8 +160,7 @@ void tst_QEventDispatcher::registerTimer()
// do the same again for the coarse timer
receivedEventType = -1;
timerIdFromEvent = -1;
QVERIFY(eventDispatcher->processEvents(QEventLoop::WaitForMoreEvents));
QCOMPARE(receivedEventType, int(QEvent::Timer));
QTRY_COMPARE_WITH_TIMEOUT(receivedEventType, int(QEvent::Timer), CoarseTimerInterval * 2);
QCOMPARE(timerIdFromEvent, coarseTimerId);
// now unregister it and make sure it's gone
eventDispatcher->unregisterTimer(coarseTimerId);