File tree Expand file tree Collapse file tree 2 files changed +40
-2
lines changed
Expand file tree Collapse file tree 2 files changed +40
-2
lines changed Original file line number Diff line number Diff line change @@ -81,7 +81,7 @@ struct Groot2Publisher::PImpl
8181
8282 std::string tree_xml;
8383
84- std::atomic_bool active_server = false ;
84+ std::atomic_bool active_server = true ;
8585 std::thread server_thread;
8686
8787 std::mutex status_mutex;
@@ -241,7 +241,6 @@ void Groot2Publisher::serverLoop()
241241{
242242 auto const serialized_uuid = CreateRandomUUID ();
243243
244- _p->active_server = true ;
245244 auto & socket = _p->server ;
246245
247246 auto sendErrorReply = [&socket](const std::string& msg) {
Original file line number Diff line number Diff line change 1+ #include < chrono>
2+ #include < future>
3+
4+ #include < behaviortree_cpp/loggers/groot2_protocol.h>
5+ #include < behaviortree_cpp/loggers/groot2_publisher.h>
6+ #include < gtest/gtest.h>
7+
8+ using namespace std ::chrono_literals;
9+
10+ namespace
11+ {
12+ static const char * xml_text = R"(
13+ <root BTCPP_format="4">
14+ <BehaviorTree ID="MainTree">
15+ <ThrowRuntimeError/>
16+ </BehaviorTree>
17+ </root>
18+ )" ;
19+
20+ void throwRuntimeError ()
21+ {
22+ BT::BehaviorTreeFactory factory;
23+ factory.registerSimpleAction (" ThrowRuntimeError" , [](BT::TreeNode&) {
24+ throw BT::RuntimeError (" Oops!" );
25+ return BT::NodeStatus::FAILURE;
26+ });
27+
28+ auto tree = factory.createTreeFromText (xml_text);
29+ BT::Groot2Publisher publisher (tree);
30+ EXPECT_THROW (tree.tickOnce (), BT::RuntimeError);
31+ }
32+ } // namespace
33+
34+ TEST (Groot2PublisherTest, EnsureNoInfiniteLoopOnThrow)
35+ {
36+ auto fut = std::async (std::launch::async, throwRuntimeError);
37+ auto status = fut.wait_for (1s);
38+ ASSERT_EQ (status, std::future_status::ready) << " Function did not finish (possible infinite loop)" ;
39+ }
You can’t perform that action at this time.
0 commit comments