From 1ce3585305febbd2fed6899cad0c58729991ec43 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Wed, 12 Feb 2020 17:50:44 +0100 Subject: [PATCH] Detect double timer during single timeout in registerTimer test, and skip MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We observe this happening on macOS in the CI system, and it might happen if a VM doesn't get CPU cycles for long enough time so that two timers time out. Then event processing will process two timer events, and we overwrite the timerIdFromEvent with the second event. Instead, skip the test when this happens. This is an ammendment to 5c520f4b0ad4b539dc0184c764ca9f12c98730d9 Fixes: QTBUG-71751 Reviewed-by: Timur Pocheptsov Reviewed-by: Tor Arne Vestbø (cherry picked from commit 67491e2df5357706dbf88ddaf1f030ff095b4528) Change-Id: I30eef8cfc94988e6cad500dd5e6722488c2985be --- .../qeventdispatcher/tst_qeventdispatcher.cpp | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/tests/auto/corelib/kernel/qeventdispatcher/tst_qeventdispatcher.cpp b/tests/auto/corelib/kernel/qeventdispatcher/tst_qeventdispatcher.cpp index 6f65932e5f..ed44026805 100644 --- a/tests/auto/corelib/kernel/qeventdispatcher/tst_qeventdispatcher.cpp +++ b/tests/auto/corelib/kernel/qeventdispatcher/tst_qeventdispatcher.cpp @@ -45,8 +45,10 @@ class tst_QEventDispatcher : public QObject Q_OBJECT QAbstractEventDispatcher *eventDispatcher; - int receivedEventType; - int timerIdFromEvent; + + int receivedEventType = -1; + int timerIdFromEvent = -1; + bool doubleTimer = false; protected: bool event(QEvent *e); @@ -54,9 +56,7 @@ protected: public: inline tst_QEventDispatcher() : QObject(), - eventDispatcher(QAbstractEventDispatcher::instance(thread())), - receivedEventType(-1), - timerIdFromEvent(-1) + eventDispatcher(QAbstractEventDispatcher::instance(thread())) { } private slots: @@ -74,6 +74,9 @@ bool tst_QEventDispatcher::event(QEvent *e) switch (receivedEventType = e->type()) { case QEvent::Timer: { + // sometimes, two timers fire during a single QTRY_xxx wait loop + if (timerIdFromEvent != -1) + doubleTimer = true; timerIdFromEvent = static_cast(e)->timerId(); return true; } @@ -219,12 +222,17 @@ void tst_QEventDispatcher::registerTimer() // process events, waiting for the next event... this should only fire the precise timer receivedEventType = -1; timerIdFromEvent = -1; + doubleTimer = false; QTRY_COMPARE_WITH_TIMEOUT(receivedEventType, int(QEvent::Timer), PreciseTimerInterval * 2); + #ifdef Q_OS_DARWIN + if (doubleTimer) + QSKIP("Double timer during a single timeout - aborting test as flaky on macOS"); if (timerIdFromEvent != timers.preciseTimerId() && elapsedTimer.elapsed() > PreciseTimerInterval * 3) QSKIP("Ignore flaky test behavior due to VM scheduling on macOS"); #endif + QCOMPARE(timerIdFromEvent, timers.preciseTimerId()); // now unregister it and make sure it's gone timers.unregister(timers.preciseTimerId()); @@ -238,8 +246,12 @@ void tst_QEventDispatcher::registerTimer() // do the same again for the coarse timer receivedEventType = -1; timerIdFromEvent = -1; + doubleTimer = false; QTRY_COMPARE_WITH_TIMEOUT(receivedEventType, int(QEvent::Timer), CoarseTimerInterval * 2); + #ifdef Q_OS_DARWIN + if (doubleTimer) + QSKIP("Double timer during a single timeout - aborting test as flaky on macOS"); if (timerIdFromEvent != timers.coarseTimerId() && elapsedTimer.elapsed() > CoarseTimerInterval * 3) QSKIP("Ignore flaky test behavior due to VM scheduling on macOS");