summaryrefslogtreecommitdiff
path: root/test/util/async_task.test.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/util/async_task.test.cpp')
-rw-r--r--test/util/async_task.test.cpp43
1 files changed, 43 insertions, 0 deletions
diff --git a/test/util/async_task.test.cpp b/test/util/async_task.test.cpp
index 214e490fd8..8c79c51405 100644
--- a/test/util/async_task.test.cpp
+++ b/test/util/async_task.test.cpp
@@ -169,4 +169,47 @@ TEST(AsyncTask, scheduleAndReplyValue) {
auto sheduler = Scheduler::GetBackground();
sheduler->scheduleAndReplyValue(runInBackground, onResult);
loop.run();
+}
+
+TEST(AsyncTask, SequencedScheduler) {
+ RunLoop loop;
+ std::thread::id caller_id = std::this_thread::get_id();
+ std::thread::id bg_id;
+ int count = 0;
+
+ auto first = [caller_id, &bg_id, &count]() {
+ EXPECT_EQ(0, count);
+ bg_id = std::this_thread::get_id();
+ EXPECT_NE(caller_id, bg_id);
+ count++;
+ };
+ auto second = [&bg_id, &count]() {
+ EXPECT_EQ(1, count);
+ EXPECT_EQ(bg_id, std::this_thread::get_id());
+ count++;
+ };
+ auto third = [&bg_id, &count, &loop]() {
+ EXPECT_EQ(2, count);
+ EXPECT_EQ(bg_id, std::this_thread::get_id());
+ loop.stop();
+ };
+
+ auto sheduler = Scheduler::GetSequenced();
+
+ sheduler->schedule(first);
+ sheduler->schedule(second);
+ sheduler->schedule(third);
+ loop.run();
+}
+
+TEST(AsyncTask, MultipleSequencedSchedulers) {
+ std::vector<std::shared_ptr<Scheduler>> shedulers;
+
+ for (int i = 0; i < 10; ++i) {
+ auto scheduler = Scheduler::GetSequenced();
+ EXPECT_TRUE(std::none_of(
+ shedulers.begin(), shedulers.end(), [&scheduler](const auto &item) { return item == scheduler; }));
+ shedulers.emplace_back(std::move(scheduler));
+ }
+ EXPECT_EQ(shedulers.front(), Scheduler::GetSequenced());
} \ No newline at end of file