@@ -18,6 +18,17 @@ static const char* xml_text = R"(
1818</root>
1919)" ;
2020
21+ static const char * xml_text_sequence = R"(
22+ <root BTCPP_format="4">
23+ <BehaviorTree ID="MainTree">
24+ <Sequence>
25+ <AlwaysSuccess/>
26+ <ThrowRuntimeError/>
27+ </Sequence>
28+ </BehaviorTree>
29+ </root>
30+ )" ;
31+
2132void throwRuntimeError ()
2233{
2334 BT::BehaviorTreeFactory factory;
@@ -46,3 +57,50 @@ TEST(Groot2PublisherTest, EnsureNoInfiniteLoopOnThrow)
4657 },
4758 ::testing::ExitedWithCode (EXIT_SUCCESS), ".*");
4859}
60+
61+ // Test that destructor completes quickly even after exception
62+ // This test runs multiple times to catch race conditions
63+ TEST (Groot2PublisherTest, DestructorCompletesAfterException)
64+ {
65+ for (int i = 0 ; i < 5 ; i++)
66+ {
67+ BT::BehaviorTreeFactory factory;
68+ factory.registerSimpleAction (" ThrowRuntimeError" ,
69+ [](BT::TreeNode&) -> BT::NodeStatus {
70+ throw BT::RuntimeError (" Test exception" );
71+ });
72+
73+ auto tree = factory.createTreeFromText (xml_text);
74+ BT::Groot2Publisher publisher (tree, 1667 + i * 2 );
75+ EXPECT_THROW (tree.tickExactlyOnce (), BT::RuntimeError);
76+ }
77+ }
78+
79+ // Test that destructor completes quickly when tree has multiple nodes
80+ TEST (Groot2PublisherTest, DestructorCompletesWithMultipleNodes)
81+ {
82+ BT::BehaviorTreeFactory factory;
83+ factory.registerSimpleAction (" ThrowRuntimeError" , [](BT::TreeNode&) -> BT::NodeStatus {
84+ throw BT::RuntimeError (" Test exception in sequence" );
85+ });
86+
87+ auto tree = factory.createTreeFromText (xml_text_sequence);
88+ BT::Groot2Publisher publisher (tree, 1677 );
89+ EXPECT_THROW (tree.tickExactlyOnce (), BT::RuntimeError);
90+ }
91+
92+ // Test rapid creation and destruction of publishers
93+ TEST (Groot2PublisherTest, RapidCreateDestroy)
94+ {
95+ for (int i = 0 ; i < 3 ; i++)
96+ {
97+ BT::BehaviorTreeFactory factory;
98+ factory.registerSimpleAction (
99+ " ThrowRuntimeError" ,
100+ [](BT::TreeNode&) -> BT::NodeStatus { throw BT::RuntimeError (" Rapid test" ); });
101+
102+ auto tree = factory.createTreeFromText (xml_text);
103+ BT::Groot2Publisher publisher (tree, 1687 + i * 2 );
104+ EXPECT_THROW (tree.tickExactlyOnce (), BT::RuntimeError);
105+ }
106+ }
0 commit comments