Add unit tests for ThreadContext
This commit is contained in:
@@ -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<TestObject> thread({"Test", ThreadType::Worker, ThreadPriority::Low}, tid);
|
||||
|
||||
thread.invokeWithResult<bool>(&TestObject::checkContext, [&] (bool inTestThreadContext) {
|
||||
EXPECT_EQ(inTestThreadContext, true);
|
||||
loop.stop();
|
||||
});
|
||||
});
|
||||
|
||||
uv_run(uv_default_loop(), UV_RUN_DEFAULT);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user