From 0a9f3ce3c87b6c54e7492f9e263f9e84c0cb62d0 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Sat, 5 Feb 2022 19:35:32 +0100 Subject: [PATCH] Make time sensitive QScrollBar test fault tolerant The auto-repeat timer of QScrollBar kicks in after 50ms, so if the test takes too long and the timer fires during the qWait call or during event delivery, then we might get multiple valueChanged emissions. Detect that scenario and allow the test to XFAIL if things take a significant time (more than 40ms vs the expected 1ms). Pick-to: 6.3 6.2 Change-Id: Ie90aadc62372397db695fd2b34fe1f5252ce8d37 Reviewed-by: Shawn Rutledge --- tests/auto/widgets/widgets/qscrollbar/tst_qscrollbar.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/auto/widgets/widgets/qscrollbar/tst_qscrollbar.cpp b/tests/auto/widgets/widgets/qscrollbar/tst_qscrollbar.cpp index 471a9bd3e4..fdd9ded575 100644 --- a/tests/auto/widgets/widgets/qscrollbar/tst_qscrollbar.cpp +++ b/tests/auto/widgets/widgets/qscrollbar/tst_qscrollbar.cpp @@ -192,13 +192,20 @@ void tst_QScrollBar::QTBUG_42871() QMouseEvent mousePressEvent(QEvent::MouseButtonPress, pressPoint, globalPressPoint, Qt::LeftButton, Qt::LeftButton, {}); QApplication::sendEvent(&scrollBarWidget, &mousePressEvent); + QElapsedTimer timer; + timer.start(); QTest::qWait(1); QMouseEvent mouseReleaseEvent(QEvent::MouseButtonRelease, pressPoint, globalPressPoint, Qt::LeftButton, Qt::LeftButton, {}); QApplication::sendEvent(&scrollBarWidget, &mouseReleaseEvent); + if (timer.elapsed() > 40) { + // took too long, we need to tolerate auto-repeat + if (myHandler.updatesCount > 1) + QEXPECT_FAIL("", "Took too long to process events, repeat timer fired", Continue); + } // Check that the action was triggered once. QCOMPARE(myHandler.updatesCount, 1); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.count(), myHandler.updatesCount); } QTEST_MAIN(tst_QScrollBar)