Make failures in QTimeLine autotest more stable.

QTimeLine appears to have very poor timing characteristics. Historical
CI logs show roughly one failure in every twenty-five test runs on
Windows, and less frequent failures on Mac and Linux.

The root of the problem seems to be that QTimeLine's currentTime
counter appears to run at a variable speed and the only guarantee is
that it is slower than wall time.  The frameChanged() test
function waited for double the expected duration of the timeline and
still found that the timeline had failed to finish in about one in every
thirty test runs.  The interpolation() test function also failed for the
same reason, though less often.

This commit makes the frameChanged test more strict so that the poor
timing will be demonstrated more often, waiting only 1.5 times the
duration instead of double the duration.  It also makes the test fail
gracefully so that this known issue won't disrupt CI when the test is
made significant in a later commit.

Task-number: QTBUG-24796
Change-Id: If469d43abb662e24445a9da619052eea9cf7c581
Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com>
This commit is contained in:
Jason McDonald 2012-04-16 23:47:19 +10:00 committed by Qt by Nokia
parent 5192b06ccb
commit 1bbd9d8ee5

View File

@ -369,6 +369,8 @@ void tst_QTimeLine::interpolation()
QCOMPARE(timeLine.state(), QTimeLine::Running);
// Smooth accellerates slowly so in the beginning so it is farther behind
if (firstValue >= timeLine.currentFrame())
QEXPECT_FAIL("", "QTBUG-24796: QTimeLine exhibits inconsistent timing behaviour", Abort);
QVERIFY(firstValue < timeLine.currentFrame());
QTest::qWait(200);
QVERIFY(endValue > timeLine.currentFrame());
@ -457,24 +459,33 @@ void tst_QTimeLine::toggleDirection()
void tst_QTimeLine::frameChanged()
{
QTimeLine timeLine;
timeLine.setCurveShape(QTimeLine::LinearCurve);
timeLine.setFrameRange(0,9);
timeLine.setUpdateInterval(1000);
timeLine.setUpdateInterval(800);
QSignalSpy spy(&timeLine, SIGNAL(frameChanged(int)));
QVERIFY(spy.isValid());
timeLine.start();
QTest::qWait(timeLine.duration()*2);
QCOMPARE(timeLine.state(), QTimeLine::NotRunning);
// Probably 10
QVERIFY(spy.count() <= 10 && spy.count() > 0);
// Test what happens when duration expires before all frames are emitted.
timeLine.start();
QTest::qWait(timeLine.duration()/2);
QCOMPARE(timeLine.state(), QTimeLine::Running);
QCOMPARE(spy.count(), 0);
QTest::qWait(timeLine.duration());
if (timeLine.state() != QTimeLine::NotRunning)
QEXPECT_FAIL("", "QTBUG-24796: QTimeLine runs slower than it should", Abort);
QCOMPARE(timeLine.state(), QTimeLine::NotRunning);
if (spy.count() != 1)
QEXPECT_FAIL("", "QTBUG-24796: QTimeLine runs slower than it should", Abort);
QCOMPARE(spy.count(), 1);
// Test what happens when the frames are all emitted well before duration expires.
timeLine.setUpdateInterval(5);
spy.clear();
timeLine.setCurrentTime(0);
timeLine.start();
QTest::qWait(timeLine.duration()*2);
QCOMPARE(timeLine.state(), QTimeLine::NotRunning);
// Probably 1
QVERIFY(spy.count() <= 10 && spy.count() > 0);
QCOMPARE(spy.count(), 10);
}
void tst_QTimeLine::stopped()