Fix flakiness in tst_QApplication::testDeleteLater

DeleteLaterWidget is a main application window of the test. So, its
show() function should be called explicitly before starting the main
event loop. Otherwise, it remains hidden for the whole time, which
causes an incorrect emission of QApplication::lastWindowClosed signal
when a dialog window is closed in the middle of the test.

Also, fix synchronization between deferred deletion and timer event.

Change-Id: Id3ce5adbcd9e5e22508825c52025eeea70202354
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Alex Trotsenko 2020-03-31 16:43:54 +03:00
parent 333d7e6de4
commit 274e973dbe

View File

@ -1229,6 +1229,11 @@ void DeleteLaterWidget::runTest()
QCoreApplication::processEvents();
// At this point, the event queue is empty. As we want a deferred
// deletion to occur before the timer event, we should provoke the
// event dispatcher for the next spin.
QCoreApplication::eventDispatcher()->interrupt();
QVERIFY(!stillAlive); // verify at the end to make test terminate
}
@ -1258,8 +1263,10 @@ void tst_QApplication::testDeleteLater()
QObject *stillAlive = wgt->findChild<QObject*>("deleteLater");
QVERIFY(stillAlive);
wgt->show();
QCoreApplication::exec();
QVERIFY(wgt->isHidden());
delete wgt;
}