diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2021-08-11 09:49:11 +0200 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2021-08-23 10:53:48 +0200 |
commit | 5e361d08a3ccb4ce22b23ec190cd01375066a8a7 (patch) | |
tree | 9eb9a8680dfe1a749b84ed08cbe44cc9ec454ac9 /tests | |
parent | 56082c28fe89d204822862853961f292ac42d96b (diff) |
Attempt to unwedge tst_QThread::wait3_slowDestructor()
When the test failed, it never released the blocking slot, so the
tested thread remained blocked indefinitely. Blacklisting doesn't
rescue that: the test run gets killed by Coin's watchdog.
Use a QScopeGuard() to release the clocked slot on failure.
replacing the release that was happening only on success.
As drive-by clean-up, smarten up the code a little and remove an
unused enum.
Change-Id: Ie035dafe6e4b1d82aea5de38ceb31c0f7fcf81d7
Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
(cherry picked from commit 2684deaf26e7c7af1ac504f562231a4cc4fbd733)
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/corelib/thread/qthread/tst_qthread.cpp | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/tests/auto/corelib/thread/qthread/tst_qthread.cpp b/tests/auto/corelib/thread/qthread/tst_qthread.cpp index 7be2f48758..bfcb66d15e 100644 --- a/tests/auto/corelib/thread/qthread/tst_qthread.cpp +++ b/tests/auto/corelib/thread/qthread/tst_qthread.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. @@ -36,6 +36,7 @@ #include <qwaitcondition.h> #include <qdebug.h> #include <qmetaobject.h> +#include <qscopeguard.h> #ifdef Q_OS_UNIX #include <pthread.h> @@ -1082,8 +1083,8 @@ void tst_QThread::wait2() qPrintable(msgElapsed(elapsed))); } - -class SlowSlotObject : public QObject { +class SlowSlotObject : public QObject +{ Q_OBJECT public: QMutex mutex; @@ -1099,22 +1100,23 @@ void tst_QThread::wait3_slowDestructor() { SlowSlotObject slow; QThread thread; - QObject::connect(&thread, SIGNAL(finished()), &slow, SLOT(slowSlot()), Qt::DirectConnection); - - enum { WaitTime = 1800 }; + QObject::connect(&thread, &QThread::finished, + &slow, &SlowSlotObject::slowSlot, Qt::DirectConnection); QElapsedTimer timer; thread.start(); thread.quit(); - //the quit function will cause the thread to finish and enter the slowSlot that is blocking + // Calling quit() will cause the thread to finish and enter the blocking slowSlot(). timer.start(); - QVERIFY(!thread.wait(Waiting_Thread::WaitTime)); - qint64 elapsed = timer.elapsed(); - QVERIFY2(elapsed >= Waiting_Thread::WaitTime - 1, qPrintable(QString::fromLatin1("elapsed: %1").arg(elapsed))); - - slow.cond.wakeOne(); - //now the thread should finish quickly + { + // Ensure thread finishes quickly after the checks - regardless of success: + const auto wakeSlow = qScopeGuard([&slow]() -> void { slow.cond.wakeOne(); }); + QVERIFY(!thread.wait(Waiting_Thread::WaitTime)); + const qint64 elapsed = timer.elapsed(); + QVERIFY2(elapsed >= Waiting_Thread::WaitTime - 1, + qPrintable(QString::fromLatin1("elapsed: %1").arg(elapsed))); + } QVERIFY(thread.wait(one_minute)); } |