From d95809470c3a2e3d57d43b6439515d12427f6de1 Mon Sep 17 00:00:00 2001 From: Sona Kurazyan Date: Mon, 5 Jul 2021 17:37:58 +0200 Subject: [PATCH] tst_QtConcurrentThreadEngine: fix the threadCount() test Enable the check, that has been disabled because of instability, which makes the test-case useless. The reason for instability probably was that it doesn't always start maxThreadCount number of threads: it could be less if the workers reuse the thread pool's already created threads (if possible) instead of creating new one each time. But we can at least make sure, that we're not starting more threads than expected. Task-number: QTBUG-94463 Change-Id: I8e498c377d86c49758bde0114fe6f7e0432fe993 Reviewed-by: Andrei Golubev Reviewed-by: Andreas Buhr (cherry picked from commit 42f2a9c5ce8b28186960499ad92754c40aa04ac5) Reviewed-by: Qt Cherry-pick Bot --- .../tst_qtconcurrentthreadengine.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/tests/auto/concurrent/qtconcurrentthreadengine/tst_qtconcurrentthreadengine.cpp b/tests/auto/concurrent/qtconcurrentthreadengine/tst_qtconcurrentthreadengine.cpp index 85f83c61f76..12a7aa4bf0a 100644 --- a/tests/auto/concurrent/qtconcurrentthreadengine/tst_qtconcurrentthreadengine.cpp +++ b/tests/auto/concurrent/qtconcurrentthreadengine/tst_qtconcurrentthreadengine.cpp @@ -255,25 +255,21 @@ public: void tst_QtConcurrentThreadEngine::threadCount() { - //QTBUG-23333: This test is unstable - const int repeats = 10; for (int i = 0; i < repeats; ++i) { (new ThreadCountUser())->startAsynchronously().waitForFinished(); const auto count = threads.count(); - const auto count_expected = QThreadPool::globalInstance()->maxThreadCount(); - if (count != count_expected) - QEXPECT_FAIL("", "QTBUG-23333", Abort); - QCOMPARE(count, count_expected); + const auto maxThreadCount = QThreadPool::globalInstance()->maxThreadCount(); + QVERIFY(count <= maxThreadCount); + QVERIFY(!threads.contains(QThread::currentThread())); } // Set the finish flag immediately, this should give us one thread only. for (int i = 0; i < repeats; ++i) { (new ThreadCountUser(true /*finishImmediately*/))->startAsynchronously().waitForFinished(); const auto count = threads.count(); - if (count != 1) - QEXPECT_FAIL("", "QTBUG-23333", Abort); QCOMPARE(count, 1); + QVERIFY(!threads.contains(QThread::currentThread())); } }