From 7b9f01e0f468b1adf4b97960f4960bf9019ea1a4 Mon Sep 17 00:00:00 2001 From: Axel Spoerl Date: Tue, 1 Nov 2022 10:44:33 +0100 Subject: [PATCH] Stabilize flakiness in tst_QWidget::raise() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The test function raise() occasionally failed because of unexpected paint events being counted. This is due to a QTRY_VERIFY returning after consumption of the first paint event. If more than one paint event got posted, it will be delivered and counted when no more paint events are expected. This patch ensures that all paint events are consumed before resetting the count and expecting no more paint events. Fixes: QTBUG-68175 Change-Id: I3e91a34e851da4bd01c7429e824d2b9101077a06 Reviewed-by: Tor Arne Vestbø Reviewed-by: Richard Moe Gustavsen (cherry picked from commit a45a1b8674d0982828d75440041a67fdb3da74f9) Reviewed-by: Qt Cherry-pick Bot --- tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp index 1404aff4592..c9152cc57cf 100644 --- a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp +++ b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp @@ -3707,7 +3707,8 @@ void tst_QWidget::raise() for (int i = 0; i < 5; ++i) child2->raise(); - QTest::qWait(50); + QVERIFY(QTest::qWaitForWindowExposed(child2)); + QApplication::processEvents(); // process events that could be triggered by raise(); for (UpdateWidget *child : std::as_const(allChildren)) { int expectedPaintEvents = child == child2 ? 1 : 0; @@ -3736,6 +3737,7 @@ void tst_QWidget::raise() onTop->show(); QVERIFY(QTest::qWaitForWindowExposed(&topLevel)); QTRY_VERIFY(onTop->numPaintEvents > 0); + QApplication::processEvents(); // process remaining paint events if there's more than one onTop->reset(); // Reset all the children. @@ -3744,7 +3746,8 @@ void tst_QWidget::raise() for (int i = 0; i < 5; ++i) child3->raise(); - QTest::qWait(50); + QVERIFY(QTest::qWaitForWindowExposed(child3)); + QApplication::processEvents(); // process events that could be triggered by raise(); QCOMPARE(onTop->numPaintEvents, 0); QCOMPARE(onTop->numZOrderChangeEvents, 0);