diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-03-31 12:09:21 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-03-31 12:09:21 +0200 |
commit | ef9e47279a9d066ccb93ff1946d20d3b13953957 (patch) | |
tree | 83f7dba41820e0d4e037f1b54c6344ac2480c8e6 /async/autotests/asynctest.cpp | |
parent | 42f32ea5865c95028c577000e15e8a8631d16e74 (diff) | |
download | sink-ef9e47279a9d066ccb93ff1946d20d3b13953957.tar.gz sink-ef9e47279a9d066ccb93ff1946d20d3b13953957.zip |
Attempt of a description how async is supposed to work, failing async lifetime tests.
Diffstat (limited to 'async/autotests/asynctest.cpp')
-rw-r--r-- | async/autotests/asynctest.cpp | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/async/autotests/asynctest.cpp b/async/autotests/asynctest.cpp index 1074ff0..85f5ea5 100644 --- a/async/autotests/asynctest.cpp +++ b/async/autotests/asynctest.cpp | |||
@@ -65,6 +65,9 @@ private Q_SLOTS: | |||
65 | void testChainingRunningJob(); | 65 | void testChainingRunningJob(); |
66 | void testChainingFinishedJob(); | 66 | void testChainingFinishedJob(); |
67 | 67 | ||
68 | void testLifetimeWithoutHandle(); | ||
69 | void testLifetimeWithHandle(); | ||
70 | |||
68 | void benchmarkSyncThenExecutor(); | 71 | void benchmarkSyncThenExecutor(); |
69 | 72 | ||
70 | private: | 73 | private: |
@@ -558,7 +561,56 @@ void AsyncTest::testChainingFinishedJob() | |||
558 | QCOMPARE(future2.value(), 84); | 561 | QCOMPARE(future2.value(), 84); |
559 | } | 562 | } |
560 | 563 | ||
564 | /* | ||
565 | * We want to be able to execute jobs without keeping a handle explicitly alive. | ||
566 | * If the future handle inside the continuation would keep the executor alive, that would probably already work. | ||
567 | */ | ||
568 | void AsyncTest::testLifetimeWithoutHandle() | ||
569 | { | ||
570 | bool done = false; | ||
571 | { | ||
572 | auto job = Async::start<void>([&done](Async::Future<void> &future) { | ||
573 | QTimer *timer = new QTimer(); | ||
574 | QObject::connect(timer, &QTimer::timeout, | ||
575 | [&future, &done]() { | ||
576 | done = true; | ||
577 | future.setFinished(); | ||
578 | }); | ||
579 | QObject::connect(timer, &QTimer::timeout, | ||
580 | timer, &QObject::deleteLater); | ||
581 | timer->setSingleShot(true); | ||
582 | timer->start(500); | ||
583 | }); | ||
584 | job.exec(); | ||
585 | } | ||
561 | 586 | ||
587 | QTRY_VERIFY(done); | ||
588 | } | ||
589 | |||
590 | /* | ||
591 | * The future handle should keep the executor alive, and the future reference should probably not become invalid inside the continuation, | ||
592 | * until the job is done (alternatively a copy of the future inside the continuation should work as well). | ||
593 | */ | ||
594 | void AsyncTest::testLifetimeWithHandle() | ||
595 | { | ||
596 | Async::Future<void> future; | ||
597 | { | ||
598 | auto job = Async::start<void>([](Async::Future<void> &future) { | ||
599 | QTimer *timer = new QTimer(); | ||
600 | QObject::connect(timer, &QTimer::timeout, | ||
601 | [&future]() { | ||
602 | future.setFinished(); | ||
603 | }); | ||
604 | QObject::connect(timer, &QTimer::timeout, | ||
605 | timer, &QObject::deleteLater); | ||
606 | timer->setSingleShot(true); | ||
607 | timer->start(500); | ||
608 | }); | ||
609 | future = job.exec(); | ||
610 | } | ||
611 | |||
612 | QTRY_VERIFY(future.isFinished()); | ||
613 | } | ||
562 | 614 | ||
563 | void AsyncTest::benchmarkSyncThenExecutor() | 615 | void AsyncTest::benchmarkSyncThenExecutor() |
564 | { | 616 | { |