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>
This commit is contained in:
Yoann Lopes
2016-08-10 12:53:13 +02:00
parent 07d55b154e
commit bf5c7ca718

View File

@@ -293,14 +293,19 @@ void tst_QMediaObject::notifySignals()
QFETCH(int, count); QFETCH(int, count);
QtTestMediaObject object; QtTestMediaObject object;
QSignalSpy spy(&object, SIGNAL(aChanged(int)));
object.setNotifyInterval(interval); object.setNotifyInterval(interval);
object.addPropertyWatch("a"); 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() void tst_QMediaObject::notifyInterval_data()