diff options
author | Liang Qi <liang.qi@qt.io> | 2016-08-31 08:24:21 +0200 |
---|---|---|
committer | Liang Qi <liang.qi@qt.io> | 2016-08-31 08:24:21 +0200 |
commit | f510a51dace0cb39a93b057b8fcbcbdda33a956e (patch) | |
tree | cd1dac8a78ecbb7579c59bf9f0b0d2d6fba56b4a /tests/auto/concurrent | |
parent | ccedc853a67da078ace234af7b23fbf861736f3f (diff) | |
parent | 84830fc07d65d58fce9b24b5ec8f1224b0969ac0 (diff) |
Merge remote-tracking branch 'origin/5.8' into dev
Change-Id: I843994939f126ced22f7fe978ec4403f599fc7c9
Diffstat (limited to 'tests/auto/concurrent')
-rw-r--r-- | tests/auto/concurrent/qtconcurrentrun/tst_qtconcurrentrun.cpp | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/auto/concurrent/qtconcurrentrun/tst_qtconcurrentrun.cpp b/tests/auto/concurrent/qtconcurrentrun/tst_qtconcurrentrun.cpp index 1b0ac7a8bc..bd53aa69fe 100644 --- a/tests/auto/concurrent/qtconcurrentrun/tst_qtconcurrentrun.cpp +++ b/tests/auto/concurrent/qtconcurrentrun/tst_qtconcurrentrun.cpp @@ -464,6 +464,19 @@ int throwFunctionReturn() return 0; } +class SlowTask : public QRunnable +{ +public: + static QAtomicInt cancel; + void run() Q_DECL_OVERRIDE { + int iter = 60; + while (--iter && !cancel.load()) + QThread::currentThread()->msleep(25); + } +}; + +QAtomicInt SlowTask::cancel; + void tst_QtConcurrentRun::exceptions() { QThreadPool pool; @@ -504,6 +517,30 @@ void tst_QtConcurrentRun::exceptions() } if (!caught) QFAIL("did not get exception"); + + caught = false; + try { + QtConcurrent::run(&pool, throwFunctionReturn).result(); + } catch (QException &) { + caught = true; + } + QVERIFY2(caught, "did not get exception"); + + // Force the task to be run on this thread. + caught = false; + QThreadPool shortPool; + shortPool.setMaxThreadCount(1); + SlowTask *st = new SlowTask(); + try { + shortPool.start(st); + QtConcurrent::run(&shortPool, throwFunctionReturn).result(); + } catch (QException &) { + caught = true; + } + + SlowTask::cancel.store(true); + + QVERIFY2(caught, "did not get exception"); } #endif |