summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorYoann Lopes <yoann.lopes@qt.io>2016-08-10 12:53:13 +0200
committerLiang Qi <liang.qi@qt.io>2016-08-10 14:19:03 +0000
commit586abbd9732f9ccce127429fe0698c25a09ecefb (patch)
tree387f394d6371dd05b541b73f77dcbb492e290eb3 /tests
parent29a46aa4ac38bf9faedbaca6d1c191d38d2db079 (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: I7f77d32a9db3d09881eadbd0dfc6b70f62757d09 Reviewed-by: Christian Stromme <christian.stromme@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/unit/qmediaobject/tst_qmediaobject.cpp11
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 31775249a..0548d1e1a 100644
--- a/tests/auto/unit/qmediaobject/tst_qmediaobject.cpp
+++ b/tests/auto/unit/qmediaobject/tst_qmediaobject.cpp
@@ -288,14 +288,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()