From bf5c7ca718a4a84e28a17ff69c4b18abee81ff93 Mon Sep 17 00:00:00 2001 From: Yoann Lopes Date: Wed, 10 Aug 2016 12:53:13 +0200 Subject: Make tst_QMediaObject::notifySignals() less flaky Rather than expecting a certain amount of signals to be fired within a fixed period, check that all the required signals are emitted and that it doesn't take longer than expected. Use a margin of error to take into account timers firing later because of high system load. Change-Id: I1569ce524e87efc47eb8d11066e509e5dc90f6f8 (cherry picked from commit 586abbd9732f9ccce127429fe0698c25a09ecefb) Reviewed-by: Christian Stromme --- tests/auto/unit/qmediaobject/tst_qmediaobject.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tests/auto/unit/qmediaobject/tst_qmediaobject.cpp b/tests/auto/unit/qmediaobject/tst_qmediaobject.cpp index 355af5676..e79d9b586 100644 --- a/tests/auto/unit/qmediaobject/tst_qmediaobject.cpp +++ b/tests/auto/unit/qmediaobject/tst_qmediaobject.cpp @@ -293,14 +293,19 @@ void tst_QMediaObject::notifySignals() QFETCH(int, count); QtTestMediaObject object; + QSignalSpy spy(&object, SIGNAL(aChanged(int))); + object.setNotifyInterval(interval); object.addPropertyWatch("a"); - QSignalSpy spy(&object, SIGNAL(aChanged(int))); + QElapsedTimer timer; + timer.start(); - QTestEventLoop::instance().enterLoop(1); + QTRY_COMPARE(spy.count(), count); - QCOMPARE(spy.count(), count); + qint64 elapsed = timer.elapsed(); + int expectedElapsed = count * interval * 1.3; // give it some margin of error + QVERIFY2(elapsed < expectedElapsed, QString("elapsed: %1, expected: %2").arg(elapsed).arg(expectedElapsed).toLocal8Bit().constData()); } void tst_QMediaObject::notifyInterval_data() -- cgit v1.2.3