diff --git a/test/miscellaneous/thread.cpp b/test/miscellaneous/thread.cpp index 9767bc4b7..f8d91bf97 100644 --- a/test/miscellaneous/thread.cpp +++ b/test/miscellaneous/thread.cpp @@ -54,6 +54,12 @@ public: return string; } + bool checkContext() const { + return ThreadContext::currentlyOn(ThreadType::Worker) + && ThreadContext::getName() == "Test" + && ThreadContext::getPriority() == ThreadPriority::Low; + } + const std::thread::id tid; }; @@ -100,3 +106,26 @@ TEST(Thread, invoke) { uv_run(uv_default_loop(), UV_RUN_DEFAULT); } + +TEST(Thread, context) { + bool isMainThreadContext = ThreadContext::currentlyOn(ThreadType::Main) + && ThreadContext::getName() == "Main" + && ThreadContext::getPriority() == ThreadPriority::Regular; + + EXPECT_EQ(isMainThreadContext, true); + + const std::thread::id tid = std::this_thread::get_id(); + + RunLoop loop(uv_default_loop()); + + loop.invoke([&] { + Thread thread({"Test", ThreadType::Worker, ThreadPriority::Low}, tid); + + thread.invokeWithResult(&TestObject::checkContext, [&] (bool inTestThreadContext) { + EXPECT_EQ(inTestThreadContext, true); + loop.stop(); + }); + }); + + uv_run(uv_default_loop(), UV_RUN_DEFAULT); +}