diff options
author | Yoann Lopes <yoann.lopes@qt.io> | 2016-08-10 12:53:13 +0200 |
---|---|---|
committer | Yoann Lopes <yoann.lopes@qt.io> | 2016-09-20 15:10:53 +0000 |
commit | bf5c7ca718a4a84e28a17ff69c4b18abee81ff93 (patch) | |
tree | 8b91103ba8e91b04e73f022837773817751eabc3 /tests | |
parent | 07d55b154e19f3f4f8525b541c44500273be70ab (diff) |
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 <christian.stromme@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/unit/qmediaobject/tst_qmediaobject.cpp | 11 |
1 files 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() |