Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/loggers/groot2_publisher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ struct Groot2Publisher::PImpl

std::string tree_xml;

std::atomic_bool active_server = false;
std::atomic_bool active_server = true;
std::thread server_thread;

std::mutex status_mutex;
Expand Down Expand Up @@ -241,7 +241,6 @@ void Groot2Publisher::serverLoop()
{
auto const serialized_uuid = CreateRandomUUID();

_p->active_server = true;
auto& socket = _p->server;

auto sendErrorReply = [&socket](const std::string& msg) {
Expand Down
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ set(BT_TESTS
gtest_enums.cpp
gtest_factory.cpp
gtest_fallback.cpp
gtest_groot2_publisher.cpp
gtest_parallel.cpp
gtest_preconditions.cpp
gtest_ports.cpp
Expand Down
44 changes: 44 additions & 0 deletions tests/gtest_groot2_publisher.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include <chrono>
#include <future>

#include <behaviortree_cpp/loggers/groot2_protocol.h>
#include <behaviortree_cpp/loggers/groot2_publisher.h>
#include <gtest/gtest.h>

Comment thread
coderabbitai[bot] marked this conversation as resolved.
using namespace std::chrono_literals;

namespace
{
static const char* xml_text = R"(
<root BTCPP_format="4">
<BehaviorTree ID="MainTree">
<ThrowRuntimeError/>
</BehaviorTree>
</root>
)";

void throwRuntimeError()
{
BT::BehaviorTreeFactory factory;
factory.registerSimpleAction("ThrowRuntimeError", [](BT::TreeNode&) {
throw BT::RuntimeError("Oops!");
return BT::NodeStatus::FAILURE;
});

auto tree = factory.createTreeFromText(xml_text);
BT::Groot2Publisher publisher(tree);
EXPECT_THROW(tree.tickOnce(), BT::RuntimeError);
}
} // namespace

TEST(Groot2PublisherTest, EnsureNoInfiniteLoopOnThrow)
{
auto fut = std::async(std::launch::async, throwRuntimeError);
auto status = fut.wait_for(1s);
EXPECT_EQ(status, std::future_status::ready);

if(status != std::future_status::ready)
{
std::exit(1); // Force exit to avoid destructor blocking
}
}
Loading