From 46c1e609893b09a61d70dda3589e6b8d25261468 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Sun, 13 Sep 2020 13:15:56 +0200 Subject: Restore qWait() implementation qWait() and qWaitFor() have one subtle difference in behavior, where qWait passes the remaining time to processEvents() and qWaitFor() does not. This lead to instability on timing sensitive tests on macOS. Amends 1abea5f5f13b4b8ec2a1c282e643b791cea12f30 Change-Id: I20f516813ca67d9e86de468c4403e475f08edc26 Reviewed-by: Volker Hilsheimer --- src/corelib/kernel/qtestsupport_core.cpp | 20 ++++++++++++++++++++ src/corelib/kernel/qtestsupport_core.h | 5 +---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/corelib/kernel/qtestsupport_core.cpp b/src/corelib/kernel/qtestsupport_core.cpp index 02dd5ad04d..f5b6ed18cd 100644 --- a/src/corelib/kernel/qtestsupport_core.cpp +++ b/src/corelib/kernel/qtestsupport_core.cpp @@ -105,5 +105,25 @@ Q_CORE_EXPORT void QTest::qSleep(int ms) \sa QTest::qSleep(), QSignalSpy::wait() */ +Q_CORE_EXPORT void QTest::qWait(int ms) +{ + // Ideally this method would be implemented in terms of qWaitFor, with + // a predicate that always returns false, but due to a compiler bug in + // GCC 6 we can't do that. + + Q_ASSERT(QCoreApplication::instance()); + + QDeadlineTimer timer(ms, Qt::PreciseTimer); + int remaining = ms; + do { + QCoreApplication::processEvents(QEventLoop::AllEvents, remaining); + QCoreApplication::sendPostedEvents(nullptr, QEvent::DeferredDelete); + remaining = timer.remainingTime(); + if (remaining <= 0) + break; + QTest::qSleep(qMin(10, remaining)); + remaining = timer.remainingTime(); + } while (remaining > 0); +} QT_END_NAMESPACE diff --git a/src/corelib/kernel/qtestsupport_core.h b/src/corelib/kernel/qtestsupport_core.h index 2abe70bf99..01b3fda7d9 100644 --- a/src/corelib/kernel/qtestsupport_core.h +++ b/src/corelib/kernel/qtestsupport_core.h @@ -88,10 +88,7 @@ Q_REQUIRED_RESULT static bool qWaitFor(Functor predicate, int timeout = 5000) return predicate(); // Last chance } -inline void qWait(int ms) -{ - (void)qWaitFor([]() { return false; }, ms); -} +Q_CORE_EXPORT void qWait(int ms); } // namespace QTest -- cgit v1.2.3