tests/auto/corelib/mimetypes: use local QThreadPool
Isolates the test from anything that might be going on on the globalInstance(). Enabled by the explicit thread-pool feature on QtConcurrent::run(). Add explicit timed wait (unit tests should contain as little indefinite waits as possible). Also avoids the use of QFutureSynchronizer, which makes my static QList checker go nuts, with no way of fixing it until Qt 6. Change-Id: I0829992642b2a49bb6a10ddd4b31eb3f88e3adeb Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
1b98ce1986
commit
542ba86e22
@ -41,7 +41,6 @@
|
||||
#include <QtCore/QStandardPaths>
|
||||
#include <QtCore/QTemporaryDir>
|
||||
#include <QtCore/QTextStream>
|
||||
#include <QFutureSynchronizer>
|
||||
#include <QtConcurrent/QtConcurrentRun>
|
||||
|
||||
#include <QtTest/QtTest>
|
||||
@ -844,18 +843,18 @@ void tst_QMimeDatabase::findByFile()
|
||||
|
||||
void tst_QMimeDatabase::fromThreads()
|
||||
{
|
||||
QThreadPool::globalInstance()->setMaxThreadCount(20);
|
||||
QThreadPool tp;
|
||||
tp.setMaxThreadCount(20);
|
||||
// Note that data-based tests cannot be used here (QTest::fetchData asserts).
|
||||
QFutureSynchronizer<void> sync;
|
||||
sync.addFuture(QtConcurrent::run(this, &tst_QMimeDatabase::mimeTypeForName));
|
||||
sync.addFuture(QtConcurrent::run(this, &tst_QMimeDatabase::aliases));
|
||||
sync.addFuture(QtConcurrent::run(this, &tst_QMimeDatabase::allMimeTypes));
|
||||
sync.addFuture(QtConcurrent::run(this, &tst_QMimeDatabase::icons));
|
||||
sync.addFuture(QtConcurrent::run(this, &tst_QMimeDatabase::inheritance));
|
||||
sync.addFuture(QtConcurrent::run(this, &tst_QMimeDatabase::knownSuffix));
|
||||
sync.addFuture(QtConcurrent::run(this, &tst_QMimeDatabase::mimeTypeForFileWithContent));
|
||||
sync.addFuture(QtConcurrent::run(this, &tst_QMimeDatabase::allMimeTypes)); // a second time
|
||||
// sync dtor blocks waiting for finished
|
||||
QtConcurrent::run(&tp, this, &tst_QMimeDatabase::mimeTypeForName);
|
||||
QtConcurrent::run(&tp, this, &tst_QMimeDatabase::aliases);
|
||||
QtConcurrent::run(&tp, this, &tst_QMimeDatabase::allMimeTypes);
|
||||
QtConcurrent::run(&tp, this, &tst_QMimeDatabase::icons);
|
||||
QtConcurrent::run(&tp, this, &tst_QMimeDatabase::inheritance);
|
||||
QtConcurrent::run(&tp, this, &tst_QMimeDatabase::knownSuffix);
|
||||
QtConcurrent::run(&tp, this, &tst_QMimeDatabase::mimeTypeForFileWithContent);
|
||||
QtConcurrent::run(&tp, this, &tst_QMimeDatabase::allMimeTypes); // a second time
|
||||
QVERIFY(tp.waitForDone(60000));
|
||||
}
|
||||
|
||||
#ifndef QT_NO_PROCESS
|
||||
|
Loading…
Reference in New Issue
Block a user