summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2015-05-08 14:49:32 +0200
committerKonstantin Käfer <mail@kkaefer.com>2015-05-08 16:43:18 +0200
commit8ee40a544e4b6459253056f2f1b6c812bde1cb33 (patch)
tree483a292b34e2d1f14fef8fc9e0482c58d3052a81 /test
parente20faf7a8d531689642106164b5ee53b3353fe80 (diff)
downloadqtlocation-mapboxgl-8ee40a544e4b6459253056f2f1b6c812bde1cb33.tar.gz
make WorkRequests cancelable
Diffstat (limited to 'test')
-rw-r--r--test/miscellaneous/worker.cpp27
1 files changed, 17 insertions, 10 deletions
diff --git a/test/miscellaneous/worker.cpp b/test/miscellaneous/worker.cpp
index de0654422c..3d3c781b8c 100644
--- a/test/miscellaneous/worker.cpp
+++ b/test/miscellaneous/worker.cpp
@@ -1,6 +1,7 @@
#include "../fixtures/util.hpp"
#include <mbgl/util/worker.hpp>
+#include <mbgl/util/work_request.hpp>
#include <mbgl/util/run_loop.hpp>
using namespace mbgl;
@@ -10,7 +11,7 @@ TEST(Worker, ExecutesWorkAndAfter) {
RunLoop loop(uv_default_loop());
Worker worker(1);
- WorkRequest request;
+ std::unique_ptr<WorkRequest> request;
bool didWork = false;
bool didAfter = false;
@@ -29,19 +30,22 @@ TEST(Worker, ExecutesWorkAndAfter) {
EXPECT_TRUE(didAfter);
}
-TEST(Worker, WorkRequestJoinWaitsForWorkToComplete) {
+TEST(Worker, WorkRequestDeletionWaitsForWorkToComplete) {
RunLoop loop(uv_default_loop());
Worker worker(1);
+ std::promise<void> started;
bool didWork = false;
loop.invoke([&] {
- WorkRequest request = worker.send([&] {
+ auto request = worker.send([&] {
+ started.set_value();
usleep(10000);
didWork = true;
}, [&] {});
+ started.get_future().get();
- request.join();
+ request.reset();
EXPECT_TRUE(didWork);
loop.stop();
});
@@ -53,15 +57,18 @@ TEST(Worker, WorkRequestJoinCancelsAfter) {
RunLoop loop(uv_default_loop());
Worker worker(1);
+ std::promise<void> started;
bool didAfter = false;
loop.invoke([&] {
- WorkRequest request = worker.send([&] {
+ auto request = worker.send([&] {
+ started.set_value();
}, [&] {
didAfter = true;
});
+ started.get_future().get();
- request.join();
+ request.reset();
loop.stop();
});
@@ -77,18 +84,18 @@ TEST(Worker, WorkRequestCancelsImmediately) {
loop.invoke([&] {
std::promise<void> started;
// First worker item.
- WorkRequest request1 = worker.send([&] {
+ auto request1 = worker.send([&] {
usleep(10000);
started.set_value();
}, [&] {});
- WorkRequest request2 = worker.send([&] {
+ auto request2 = worker.send([&] {
ADD_FAILURE() << "Second work item should not be invoked";
}, [&] {});
- request2.join();
+ request2.reset();
started.get_future().get();
- request1.join();
+ request1.reset();
loop.stop();
});