From 31421f8448d0192d04b95e31a0aecde2675b5988 Mon Sep 17 00:00:00 2001 From: Mikhail Pozdnyakov Date: Mon, 28 Oct 2019 17:12:58 +0200 Subject: [core] Add Scheduler::scheduleAndReplyValue() API --- test/util/async_task.test.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'test/util') diff --git a/test/util/async_task.test.cpp b/test/util/async_task.test.cpp index 682926a17d..214e490fd8 100644 --- a/test/util/async_task.test.cpp +++ b/test/util/async_task.test.cpp @@ -151,3 +151,22 @@ TEST(AsyncTask, ThreadSafety) { // a valid result, although very unlikely (I hope). EXPECT_GT(count, 0u); } + +TEST(AsyncTask, scheduleAndReplyValue) { + RunLoop loop; + std::thread::id caller_id = std::this_thread::get_id(); + + auto runInBackground = [caller_id]() -> int { + EXPECT_NE(caller_id, std::this_thread::get_id()); + return 42; + }; + auto onResult = [caller_id, &loop](int res) { + EXPECT_EQ(caller_id, std::this_thread::get_id()); + EXPECT_EQ(42, res); + loop.stop(); + }; + + auto sheduler = Scheduler::GetBackground(); + sheduler->scheduleAndReplyValue(runInBackground, onResult); + loop.run(); +} \ No newline at end of file -- cgit v1.2.1