summaryrefslogtreecommitdiffstats
path: root/tests/auto/concurrent
diff options
context:
space:
mode:
authorSona Kurazyan <sona.kurazyan@qt.io>2021-06-10 17:38:27 +0200
committerSona Kurazyan <sona.kurazyan@qt.io>2021-06-14 11:52:36 +0200
commit1bf75f2a661c05c7f1126187310d7df3f9704af5 (patch)
treeb218904f1b4da6e7ae59627af302a49c8c042d0e /tests/auto/concurrent
parent7dd4c937489451e72a671784dcd353e4c5bc16df (diff)
Remove the dead code for blocking methods from QtConcurrent
After 79fd1cb2c631b6084bf10874205d27f5b53c907a the methods for running QtConcurrent algorithms in the blocking mode aren't used anymore. Since ThreadEngineBase and ThreadEngineStarter classes aren't meant to be used externally, it should be fine to remove startBlocking() methods now. Removed the unused code and adjusted the tests accordingly. Change-Id: Ifb13820ce207869d6f720bcb5be8d35bb355fe33 Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io> Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io> Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
Diffstat (limited to 'tests/auto/concurrent')
-rw-r--r--tests/auto/concurrent/qtconcurrentiteratekernel/tst_qtconcurrentiteratekernel.cpp23
-rw-r--r--tests/auto/concurrent/qtconcurrentthreadengine/tst_qtconcurrentthreadengine.cpp124
2 files changed, 29 insertions, 118 deletions
diff --git a/tests/auto/concurrent/qtconcurrentiteratekernel/tst_qtconcurrentiteratekernel.cpp b/tests/auto/concurrent/qtconcurrentiteratekernel/tst_qtconcurrentiteratekernel.cpp
index 7fba6ed580..4163883a5b 100644
--- a/tests/auto/concurrent/qtconcurrentiteratekernel/tst_qtconcurrentiteratekernel.cpp
+++ b/tests/auto/concurrent/qtconcurrentiteratekernel/tst_qtconcurrentiteratekernel.cpp
@@ -126,7 +126,8 @@ public:
void tst_QtConcurrentIterateKernel::instantiate()
{
- startThreadEngine(new PrintFor(0, 40)).startBlocking();
+ auto future = startThreadEngine(new PrintFor(0, 40)).startAsynchronously();
+ future.waitForFinished();
QCOMPARE(iterations.loadRelaxed(), 40);
}
@@ -165,8 +166,10 @@ void tst_QtConcurrentIterateKernel::stresstest()
const int times = 50;
for (int i = 0; i < times; ++i) {
counter.storeRelaxed(0);
- CountFor f(0, iterations);
- f.startBlocking();
+ // ThreadEngine will delete f when it finishes
+ auto f = new CountFor(0, iterations);
+ auto future = f->startAsynchronously();
+ future.waitForFinished();
QCOMPARE(counter.loadRelaxed(), iterations);
}
}
@@ -174,8 +177,12 @@ void tst_QtConcurrentIterateKernel::stresstest()
void tst_QtConcurrentIterateKernel::noIterations()
{
const int times = 20000;
- for (int i = 0; i < times; ++i)
- startThreadEngine(new IterateKernel<TestIterator, void>(QThreadPool::globalInstance(), 0, 0)).startBlocking();
+ for (int i = 0; i < times; ++i) {
+ auto future = startThreadEngine(new IterateKernel<TestIterator, void>(
+ QThreadPool::globalInstance(), 0, 0))
+ .startAsynchronously();
+ future.waitForFinished();
+ }
}
QMutex threadsMutex;
@@ -230,8 +237,10 @@ void tst_QtConcurrentIterateKernel::throttling()
threads.clear();
- ThrottleFor f(0, totalIterations);
- f.startBlocking();
+ // ThreadEngine will delete f when it finishes
+ auto f = new ThrottleFor(0, totalIterations);
+ auto future = f->startAsynchronously();
+ future.waitForFinished();
QCOMPARE(iterations.loadRelaxed(), totalIterations);
diff --git a/tests/auto/concurrent/qtconcurrentthreadengine/tst_qtconcurrentthreadengine.cpp b/tests/auto/concurrent/qtconcurrentthreadengine/tst_qtconcurrentthreadengine.cpp
index c365ec4837..85f83c61f7 100644
--- a/tests/auto/concurrent/qtconcurrentthreadengine/tst_qtconcurrentthreadengine.cpp
+++ b/tests/auto/concurrent/qtconcurrentthreadengine/tst_qtconcurrentthreadengine.cpp
@@ -66,16 +66,9 @@ public:
void tst_QtConcurrentThreadEngine::runDirectly()
{
- {
- PrintUser engine;
- engine.startSingleThreaded();
- engine.startBlocking();
- }
- {
- PrintUser *engine = new PrintUser();
- QFuture<void> f = engine->startAsynchronously();
- f.waitForFinished();
- }
+ PrintUser *engine = new PrintUser();
+ QFuture<void> f = engine->startAsynchronously();
+ f.waitForFinished();
}
class StringResultUser : public ThreadEngine<QString>
@@ -108,8 +101,10 @@ public:
void tst_QtConcurrentThreadEngine::result()
{
- StringResultUser engine;
- QCOMPARE(*engine.startBlocking(), QString("Foo"));
+ // ThreadEngine will delete 'engine' when it finishes
+ auto engine = new StringResultUser();
+ auto future = engine->startAsynchronously();
+ QCOMPARE(future.result(), QString("Foo"));
}
class VoidResultUser : public ThreadEngine<void>
@@ -137,17 +132,9 @@ public:
void tst_QtConcurrentThreadEngine::runThroughStarter()
{
- {
- ThreadEngineStarter<QString> starter = startThreadEngine(new StringResultUser());
- QFuture<QString> f = starter.startAsynchronously();
- QCOMPARE(f.result(), QString("Foo"));
- }
-
- {
- ThreadEngineStarter<QString> starter = startThreadEngine(new StringResultUser());
- QString str = starter.startBlocking();
- QCOMPARE(str, QString("Foo"));
- }
+ ThreadEngineStarter<QString> starter = startThreadEngine(new StringResultUser());
+ QFuture<QString> f = starter.startAsynchronously();
+ QCOMPARE(f.result(), QString("Foo"));
}
class CancelUser : public ThreadEngine<void>
@@ -233,12 +220,6 @@ void tst_QtConcurrentThreadEngine::throttle()
f.waitForFinished();
QCOMPARE(count.loadRelaxed(), 0);
}
-
- for (int i = 0; i < repeats; ++i) {
- ThrottleAlwaysUser t;
- t.startBlocking();
- QCOMPARE(count.loadRelaxed(), 0);
- }
}
QSet<QThread *> threads;
@@ -278,17 +259,9 @@ void tst_QtConcurrentThreadEngine::threadCount()
const int repeats = 10;
for (int i = 0; i < repeats; ++i) {
- ThreadCountUser t;
- t.startBlocking();
- int count = threads.count();
- int count_expected = QThreadPool::globalInstance()->maxThreadCount() + 1; // +1 for the main thread.
- if (count != count_expected)
- QEXPECT_FAIL("", "QTBUG-23333", Abort);
- QCOMPARE(count, count_expected);
-
(new ThreadCountUser())->startAsynchronously().waitForFinished();
- count = threads.count();
- count_expected = QThreadPool::globalInstance()->maxThreadCount();
+ 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);
@@ -296,15 +269,8 @@ void tst_QtConcurrentThreadEngine::threadCount()
// Set the finish flag immediately, this should give us one thread only.
for (int i = 0; i < repeats; ++i) {
- ThreadCountUser t(true /*finishImmediately*/);
- t.startBlocking();
- int count = threads.count();
- if (count != 1)
- QEXPECT_FAIL("", "QTBUG-23333", Abort);
- QCOMPARE(count, 1);
-
(new ThreadCountUser(true /*finishImmediately*/))->startAsynchronously().waitForFinished();
- count = threads.count();
+ const auto count = threads.count();
if (count != 1)
QEXPECT_FAIL("", "QTBUG-23333", Abort);
QCOMPARE(count, 1);
@@ -450,7 +416,6 @@ public:
void tst_QtConcurrentThreadEngine::exceptions()
{
- // Asynchronous mode:
{
bool caught = false;
try {
@@ -463,32 +428,6 @@ void tst_QtConcurrentThreadEngine::exceptions()
QVERIFY2(caught, "did not get exception");
}
- // Blocking mode:
- // test throwing the exception from a worker thread.
- {
- bool caught = false;
- try {
- QtConcurrentExceptionThrower e(QThread::currentThread());
- e.startBlocking();
- } catch (const QException &) {
- caught = true;
- }
- QVERIFY2(caught, "did not get exception");
- }
-
- // test throwing the exception from the main thread (different code path)
- {
- bool caught = false;
- try {
- QtConcurrentExceptionThrower e(nullptr);
- e.startBlocking();
- } catch (const QException &) {
- caught = true;
- }
- QVERIFY2(caught, "did not get exception");
- }
-
- // Asynchronous mode:
{
bool caught = false;
try {
@@ -506,43 +445,6 @@ void tst_QtConcurrentThreadEngine::exceptions()
}
QVERIFY2(caught, "did not get exception");
}
-
- // Blocking mode:
- // test throwing the exception from a worker thread.
- {
- bool caught = false;
- try {
- IntExceptionThrower e(QThread::currentThread());
- e.startBlocking();
- } catch (const QUnhandledException &ex) {
- // Make sure the exception info is not lost
- try {
- if (ex.exception())
- std::rethrow_exception(ex.exception());
- } catch (int) {
- caught = true;
- }
- }
- QVERIFY2(caught, "did not get exception");
- }
-
- // test throwing the exception from the main thread (different code path)
- {
- bool caught = false;
- try {
- IntExceptionThrower e(nullptr);
- e.startBlocking();
- } catch (const QUnhandledException &ex) {
- // Make sure the exception info is not lost
- try {
- if (ex.exception())
- std::rethrow_exception(ex.exception());
- } catch (int) {
- caught = true;
- }
- }
- QVERIFY2(caught, "did not get exception");
- }
}
#endif