5 #include <gtest/gtest.h>
7 using namespace std::chrono;
10 using Timepoint = std::chrono::time_point<std::chrono::steady_clock>;
17 :
BT::CoroActionNode(node_name, config)
18 , will_fail_(will_fail)
23 virtual void halt()
override
25 std::cout <<
"Action was halted. doing cleanup here" << std::endl;
26 start_time_ = Timepoint::min();
44 std::cout <<
"Starting action " << std::endl;
47 if(start_time_ == Timepoint::min())
49 start_time_ = std::chrono::steady_clock::now();
52 while(std::chrono::steady_clock::now() < (start_time_ + timeout_))
54 setStatusRunningAndYield();
59 std::cout <<
"Done" << std::endl;
60 start_time_ = Timepoint::min();
88 BT::assignDefaultRemapping<SimpleCoroAction>(node_config_);
109 TEST(CoroTest, do_action_timeout)
113 BT::assignDefaultRemapping<SimpleCoroAction>(node_config_);
133 BT::assignDefaultRemapping<SimpleCoroAction>(node_config_);
135 SimpleCoroAction actionA(milliseconds(200),
false,
"action_A", node_config_);
136 SimpleCoroAction actionB(milliseconds(200),
false,
"action_B", node_config_);
149 TEST(CoroTest, OtherThreadHalt)
153 BT::assignDefaultRemapping<SimpleCoroAction>(node_config_);
155 SimpleCoroAction actionA(milliseconds(200),
false,
"action_A", node_config_);
158 std::cout <<
"----- 1 ------ " << std::endl;
159 auto handle = std::async(std::launch::async, [&]() { actionA.
halt(); });
161 std::cout <<
"----- 2 ------ " << std::endl;
164 std::cout <<
"----- 3------ " << std::endl;
165 handle = std::async(std::launch::async, [&]() { actionA.
executeTick(); });
167 std::cout <<
"----- 4 ------ " << std::endl;