Skip to content

Commit 1f408e3

Browse files
ahcordeYadunund
andauthored
Shutdown the context before context's destructor is invoked in tests (#2633)
* zenoh: Shutdown the node properly in component tests Signed-off-by: Alejandro Hernández Cordero <[email protected]> * Call rclcpp::shutdown when tearing down tests in rclcpp Signed-off-by: Yadunund <[email protected]> * Call rclcpp::shutdown when tearing down tests in rclcpp_lifecycle Signed-off-by: Yadunund <[email protected]> * Ensure context is initialized for all tests in test_publisher Signed-off-by: Yadunund <[email protected]> * Added feedback Signed-off-by: Alejandro Hernández Cordero <[email protected]> * make linters happy Signed-off-by: Alejandro Hernández Cordero <[email protected]> --------- Signed-off-by: Alejandro Hernández Cordero <[email protected]> Signed-off-by: Yadunund <[email protected]> Co-authored-by: Yadunund <[email protected]>
1 parent 63105cd commit 1f408e3

19 files changed

+99
-5
lines changed

rclcpp/test/rclcpp/executors/test_multi_threaded_executor.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ class TestMultiThreadedExecutor : public ::testing::Test
3232
{
3333
rclcpp::init(0, nullptr);
3434
}
35+
36+
static void TearDownTestCase()
37+
{
38+
rclcpp::shutdown();
39+
}
3540
};
3641

3742
constexpr std::chrono::milliseconds PERIOD_MS = 1000ms;

rclcpp/test/rclcpp/node_interfaces/test_get_node_interfaces.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class TestGetNodeInterfaces : public ::testing::Test
3838
{
3939
node.reset();
4040
wrapped_node.reset();
41+
rclcpp::shutdown();
4142
}
4243

4344
static rclcpp::Node::SharedPtr node;

rclcpp/test/rclcpp/node_interfaces/test_node_graph.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,13 @@ constexpr char absolute_namespace[] = "/ns";
4747
class TestNodeGraph : public ::testing::Test
4848
{
4949
public:
50-
void SetUp()
50+
static void SetUpTestCase()
5151
{
5252
rclcpp::init(0, nullptr);
53+
}
54+
55+
void SetUp()
56+
{
5357
node_ = std::make_shared<rclcpp::Node>(node_name, node_namespace);
5458

5559
// This dynamic cast is not necessary for the unittests, but instead is used to ensure
@@ -59,7 +63,7 @@ class TestNodeGraph : public ::testing::Test
5963
ASSERT_NE(nullptr, node_graph_);
6064
}
6165

62-
void TearDown()
66+
static void TearDownTestCase()
6367
{
6468
rclcpp::shutdown();
6569
}

rclcpp/test/rclcpp/test_externally_defined_services.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ class TestExternallyDefinedServices : public ::testing::Test
3434
{
3535
rclcpp::init(0, nullptr);
3636
}
37+
38+
static void TearDownTestCase()
39+
{
40+
rclcpp::shutdown();
41+
}
3742
};
3843

3944
void

rclcpp/test/rclcpp/test_find_weak_nodes.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ class TestFindWeakNodes : public ::testing::Test
2727
{
2828
rclcpp::init(0, nullptr);
2929
}
30+
31+
static void TearDownTestCase()
32+
{
33+
rclcpp::shutdown();
34+
}
3035
};
3136

3237
TEST_F(TestFindWeakNodes, allocator_strategy_with_weak_nodes) {

rclcpp/test/rclcpp/test_guard_condition.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ class TestGuardCondition : public ::testing::Test
2727
{
2828
rclcpp::init(0, nullptr);
2929
}
30+
31+
static void TearDownTestCase()
32+
{
33+
rclcpp::shutdown();
34+
}
3035
};
3136

3237
/*

rclcpp/test/rclcpp/test_node_global_args.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ class TestNodeWithGlobalArgs : public ::testing::Test
3232
const int argc = sizeof(args) / sizeof(const char *);
3333
rclcpp::init(argc, args);
3434
}
35+
36+
static void TearDownTestCase()
37+
{
38+
rclcpp::shutdown();
39+
}
3540
};
3641

3742
TEST_F(TestNodeWithGlobalArgs, local_arguments_before_global) {

rclcpp/test/rclcpp/test_parameter.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ class TestParameter : public ::testing::Test
3131
{
3232
rclcpp::init(0, nullptr);
3333
}
34+
35+
static void TearDownTestCase()
36+
{
37+
rclcpp::shutdown();
38+
}
3439
};
3540

3641
TEST_F(TestParameter, construct_destruct) {

rclcpp/test/rclcpp/test_parameter_client.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ class TestParameterClient : public ::testing::Test
6060
node_with_option.reset();
6161
}
6262

63+
static void TearDownTestCase()
64+
{
65+
rclcpp::shutdown();
66+
}
67+
6368
// "start_type_description_service" and "use_sim_time"
6469
const uint64_t builtin_param_count = 2;
6570
rclcpp::Node::SharedPtr node;

rclcpp/test/rclcpp/test_parameter_event_handler.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ class TestNode : public ::testing::Test
107107
param_handler.reset();
108108
}
109109

110+
static void TearDownTestCase()
111+
{
112+
rclcpp::shutdown();
113+
}
114+
110115
rcl_interfaces::msg::ParameterEvent::SharedPtr same_node_int;
111116
rcl_interfaces::msg::ParameterEvent::SharedPtr same_node_double;
112117
rcl_interfaces::msg::ParameterEvent::SharedPtr diff_node_int;

0 commit comments

Comments
 (0)