I was doing Unit Testing and finding code coverage using gtest and lcov.
My function is
void MyClass::MyFunction(const std::string& argument1, const std::string& argument2) {
std::thread([this, argument1, argument2]() {
std::unique_lock<std::mutex> live_lock_(live_mutex_);
int64_t time_stamp = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
int64_t time_to_live = myList[argument1] - (time_stamp % myList[argument1]);
cond_var_.wait_for(time_to_live_lock_, std::chrono::milliseconds(time_to_live), [this, argument1] { return cond_var_status_[argument1]; });
if (message_master_.find(argument1) != message_master_.end()) {
//something
}
}).detach();
std::cout<< "end line is executed"<<std::endl; }
and my test function is
TEST(test, test1) {
Myclass testObj;
testObj.MyFunction("arg1", "arg2");
ASSERT_EQ("","");
};
When I run the test, all codes except those inside thread are executed.
So is there any solution to call those codes inside thread too?
question from:
https://stackoverflow.com/questions/65881112/calling-a-function-which-is-inside-a-thread 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…