From 9f6f3da8eb5da4718f601cc768d5baba404ef1a6 Mon Sep 17 00:00:00 2001 From: Alex Trotsenko Date: Tue, 18 Jan 2022 19:37:33 +0200 Subject: [PATCH] tst_qeventdispatcher: avoid influence between test functions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When some test function fails (even as expected), it can leave the event dispatcher in an inconsistent state where the posted events queue might not be empty. As a result, this may break the internal logic of the next test function that is run. So, calling eventDispatcher->processEvents() after each completed function resets the event dispatcher to its initial state, which fixes the problem. Pick-to: 6.2 6.3 Change-Id: I5a54f892d09a6eca73c8fc82875ce3b9ce4a3242 Reviewed-by: Volker Hilsheimer Reviewed-by: Thiago Macieira Reviewed-by: MÃ¥rten Nordheim --- .../kernel/qeventdispatcher/tst_qeventdispatcher.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/auto/corelib/kernel/qeventdispatcher/tst_qeventdispatcher.cpp b/tests/auto/corelib/kernel/qeventdispatcher/tst_qeventdispatcher.cpp index a3732f2d95f..2fff160ceb0 100644 --- a/tests/auto/corelib/kernel/qeventdispatcher/tst_qeventdispatcher.cpp +++ b/tests/auto/corelib/kernel/qeventdispatcher/tst_qeventdispatcher.cpp @@ -65,6 +65,8 @@ public: private slots: void initTestCase(); + void cleanup(); + void registerTimer(); /* void registerSocketNotifier(); */ // Not implemented here, see tst_QSocketNotifier instead @@ -111,6 +113,12 @@ void tst_QEventDispatcher::initTestCase() } } +// consume pending posted events to avoid impact on the next test function +void tst_QEventDispatcher::cleanup() +{ + eventDispatcher->processEvents(QEventLoop::AllEvents); +} + class TimerManager { Q_DISABLE_COPY(TimerManager)