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
Pick-to: 5.15 6.1 6.2
Change-Id: I8e498c377d86c49758bde0114fe6f7e0432fe993
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
Reviewed-by: Andreas Buhr <andreas.buhr@qt.io>
This commit is contained in:
Sona Kurazyan 2021-07-05 17:37:58 +02:00
parent e17a776157
commit 42f2a9c5ce

View File

@ -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()));
}
}