Skip to content

Commit 3fb427c

Browse files
committed
Cleanup gtest_groot2_publisher.cpp
1 parent 36d3a75 commit 3fb427c

1 file changed

Lines changed: 15 additions & 11 deletions

File tree

‎tests/gtest_groot2_publisher.cpp‎

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <chrono>
2+
#include <cstdlib>
23
#include <future>
34

45
#include <behaviortree_cpp/loggers/groot2_protocol.h>
@@ -20,25 +21,28 @@ static const char* xml_text = R"(
2021
void throwRuntimeError()
2122
{
2223
BT::BehaviorTreeFactory factory;
23-
factory.registerSimpleAction("ThrowRuntimeError", [](BT::TreeNode&) {
24+
factory.registerSimpleAction("ThrowRuntimeError", [](BT::TreeNode&) -> BT::NodeStatus {
2425
throw BT::RuntimeError("Oops!");
25-
return BT::NodeStatus::FAILURE;
2626
});
2727

2828
auto tree = factory.createTreeFromText(xml_text);
2929
BT::Groot2Publisher publisher(tree);
30-
EXPECT_THROW(tree.tickOnce(), BT::RuntimeError);
30+
EXPECT_THROW(tree.tickExactlyOnce(), BT::RuntimeError);
3131
}
3232
} // namespace
3333

3434
TEST(Groot2PublisherTest, EnsureNoInfiniteLoopOnThrow)
3535
{
36-
auto fut = std::async(std::launch::async, throwRuntimeError);
37-
auto status = fut.wait_for(1s);
38-
EXPECT_EQ(status, std::future_status::ready);
39-
40-
if(status != std::future_status::ready)
41-
{
42-
std::exit(1); // Force exit to avoid destructor blocking
43-
}
36+
EXPECT_EXIT(
37+
{
38+
auto fut = std::async(std::launch::async, throwRuntimeError);
39+
auto status = fut.wait_for(1s); // shouldn't run for more than 1 second
40+
if(status != std::future_status::ready)
41+
{
42+
std::cerr << "Test took too long. Possible infinite loop.\n";
43+
std::exit(EXIT_FAILURE);
44+
}
45+
std::exit(EXIT_SUCCESS);
46+
},
47+
::testing::ExitedWithCode(EXIT_SUCCESS), ".*");
4448
}

0 commit comments

Comments
 (0)