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

+5
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

+1
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

+6-2
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

+5
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

+5
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

+5
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

+5
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

+5
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

+5
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

+5
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;

rclcpp/test/rclcpp/test_publisher.cpp

+12-3
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@ class TestPublisher : public ::testing::Test
3838
public:
3939
static void SetUpTestCase()
4040
{
41-
if (!rclcpp::ok()) {
42-
rclcpp::init(0, nullptr);
43-
}
41+
rclcpp::init(0, nullptr);
4442
}
4543

4644
protected:
@@ -54,6 +52,11 @@ class TestPublisher : public ::testing::Test
5452
node.reset();
5553
}
5654

55+
static void TearDownTestCase()
56+
{
57+
rclcpp::shutdown();
58+
}
59+
5760
rclcpp::Node::SharedPtr node;
5861
};
5962

@@ -81,6 +84,7 @@ class TestPublisherSub : public ::testing::Test
8184
protected:
8285
static void SetUpTestCase()
8386
{
87+
rclcpp::init(0, nullptr);
8488
}
8589

8690
void SetUp()
@@ -94,6 +98,11 @@ class TestPublisherSub : public ::testing::Test
9498
node.reset();
9599
}
96100

101+
static void TearDownTestCase()
102+
{
103+
rclcpp::shutdown();
104+
}
105+
97106
rclcpp::Node::SharedPtr node;
98107
rclcpp::Node::SharedPtr subnode;
99108
};

rclcpp/test/rclcpp/test_qos_event.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ class TestQosEvent : public ::testing::Test
5252
node.reset();
5353
}
5454

55+
static void TearDownTestCase()
56+
{
57+
rclcpp::shutdown();
58+
}
59+
5560
static constexpr char topic_name[] = "test_topic";
5661
rclcpp::Node::SharedPtr node;
5762
std::function<void(test_msgs::msg::Empty::ConstSharedPtr)> message_callback;

rclcpp/test/rclcpp/test_subscription_options.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ class TestSubscriptionOptions : public ::testing::Test
5151
node.reset();
5252
}
5353

54+
static void TearDownTestCase()
55+
{
56+
rclcpp::shutdown();
57+
}
58+
5459
rclcpp::Node::SharedPtr node;
5560
};
5661

rclcpp/test/rclcpp/test_wait_set.cpp

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

3641
/*

rclcpp_components/test/test_component_manager.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ class TestComponentManager : public ::testing::Test
2828
{
2929
rclcpp::init(0, nullptr);
3030
}
31+
32+
static void TearDownTestCase()
33+
{
34+
rclcpp::shutdown();
35+
}
3136
};
3237

3338
TEST_F(TestComponentManager, get_component_resources_invalid)

rclcpp_components/test/test_component_manager_api.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ class TestComponentManager : public ::testing::Test
3333
{
3434
rclcpp::init(0, nullptr);
3535
}
36+
37+
static void TearDownTestCase()
38+
{
39+
rclcpp::shutdown();
40+
}
3641
};
3742

3843
// TODO(hidmic): split up tests once Node bring up/tear down races

rclcpp_lifecycle/test/test_callback_exceptions.cpp

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

3944
class PositiveCallbackExceptionNode : public rclcpp_lifecycle::LifecycleNode

rclcpp_lifecycle/test/test_register_custom_callbacks.cpp

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

3944
class CustomLifecycleNode : public rclcpp_lifecycle::LifecycleNode

rclcpp_lifecycle/test/test_state_machine_info.cpp

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

3944
TEST_F(TestStateMachineInfo, available_states) {

0 commit comments

Comments
 (0)