Stabilize flakiness in tst_QWidget::raise()

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ø <tor.arne.vestbo@qt.io>
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
(cherry picked from commit a45a1b8674d0982828d75440041a67fdb3da74f9)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Axel Spoerl 2022-11-01 10:44:33 +01:00 committed by Qt Cherry-pick Bot
parent 08f754d923
commit 7b9f01e0f4

View File

@ -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);