From 27bc3300d670d65b9c5332308605ef8263c3939c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dan=20Vr=C3=A1til?= Date: Fri, 3 Apr 2015 18:17:12 +0200 Subject: Async: implement progress reporting through future This is a simplified progress reporting, since it does not report progress of ther overcall Job chain, but only of individual tasks, which makes it only really useful on one-task Jobs. TODO: propagate subjob progress to the Future user gets copy of TODO: compound progress reporting (be able to report a progress of the overall Job chain) --- async/autotests/asynctest.cpp | 62 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) (limited to 'async/autotests') diff --git a/async/autotests/asynctest.cpp b/async/autotests/asynctest.cpp index 61ab8bc..7b8d430 100644 --- a/async/autotests/asynctest.cpp +++ b/async/autotests/asynctest.cpp @@ -60,6 +60,7 @@ private Q_SLOTS: void testJoinedReduce(); void testVoidReduce(); + void testProgressReporting(); void testErrorHandler(); void testChainingRunningJob(); @@ -69,6 +70,7 @@ private Q_SLOTS: void testLifetimeWithHandle(); void benchmarkSyncThenExecutor(); + void benchmarkAllTests(); private: template @@ -471,6 +473,40 @@ void AsyncTest::testVoidReduce() } +void AsyncTest::testProgressReporting() +{ + static int progress; + progress = 0; + + auto job = Async::start( + [](Async::Future &f) { + QTimer *timer = new QTimer(); + connect(timer, &QTimer::timeout, + [&f, timer]() { + f.setProgress(++progress); + if (progress == 100) { + timer->stop(); + timer->deleteLater(); + f.setFinished(); + } + }); + timer->start(1); + }); + + int progressCheck = 0; + Async::FutureWatcher watcher; + connect(&watcher, &Async::FutureWatcher::futureProgress, + [&progressCheck](qreal progress) { + progressCheck++; + // FIXME: Don't use Q_ASSERT in unit tests + Q_ASSERT((int) progress == progressCheck); + }); + watcher.setFuture(job.exec()); + watcher.future().waitForFinished(); + + QVERIFY(watcher.future().isFinished()); + QCOMPARE(progressCheck, 100); +} void AsyncTest::testErrorHandler() { @@ -634,6 +670,32 @@ void AsyncTest::benchmarkSyncThenExecutor() } } +void AsyncTest::benchmarkAllTests() +{ + QBENCHMARK { + testSyncPromises(); + testAsyncPromises(); + testAsyncPromises2(); + testNestedAsync(); + testStartValue(); + + testAsyncThen(); + testSyncThen(); + testJoinedThen(); + testVoidThen(); + + testAsyncEach(); + testSyncEach(); + testJoinedEach(); + testVoidEach(); + + testAsyncReduce(); + testSyncReduce(); + testJoinedReduce(); + testVoidReduce(); + } +} + QTEST_MAIN(AsyncTest); -- cgit v1.2.3