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
Pick-to: 6.2 6.4
Change-Id: I3e91a34e851da4bd01c7429e824d2b9101077a06
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
bb10
Axel Spoerl 2022-11-01 10:44:33 +01:00
parent 436467134e
commit a45a1b8674
1 changed files with 5 additions and 2 deletions

View File

@ -3719,7 +3719,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;
@ -3748,6 +3749,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.
@ -3756,7 +3758,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);