Skip to content

Commit

Permalink
Shutdown the context before context's destructor is invoked in tests (#…
Browse files Browse the repository at this point in the history
…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]>
  • Loading branch information
ahcorde and Yadunund authored Sep 24, 2024
1 parent 63105cd commit 1f408e3
Show file tree
Hide file tree
Showing 19 changed files with 99 additions and 5 deletions.
5 changes: 5 additions & 0 deletions rclcpp/test/rclcpp/executors/test_multi_threaded_executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ class TestMultiThreadedExecutor : public ::testing::Test
{
rclcpp::init(0, nullptr);
}

static void TearDownTestCase()
{
rclcpp::shutdown();
}
};

constexpr std::chrono::milliseconds PERIOD_MS = 1000ms;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class TestGetNodeInterfaces : public ::testing::Test
{
node.reset();
wrapped_node.reset();
rclcpp::shutdown();
}

static rclcpp::Node::SharedPtr node;
Expand Down
8 changes: 6 additions & 2 deletions rclcpp/test/rclcpp/node_interfaces/test_node_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,13 @@ constexpr char absolute_namespace[] = "/ns";
class TestNodeGraph : public ::testing::Test
{
public:
void SetUp()
static void SetUpTestCase()
{
rclcpp::init(0, nullptr);
}

void SetUp()
{
node_ = std::make_shared<rclcpp::Node>(node_name, node_namespace);

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

void TearDown()
static void TearDownTestCase()
{
rclcpp::shutdown();
}
Expand Down
5 changes: 5 additions & 0 deletions rclcpp/test/rclcpp/test_externally_defined_services.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ class TestExternallyDefinedServices : public ::testing::Test
{
rclcpp::init(0, nullptr);
}

static void TearDownTestCase()
{
rclcpp::shutdown();
}
};

void
Expand Down
5 changes: 5 additions & 0 deletions rclcpp/test/rclcpp/test_find_weak_nodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ class TestFindWeakNodes : public ::testing::Test
{
rclcpp::init(0, nullptr);
}

static void TearDownTestCase()
{
rclcpp::shutdown();
}
};

TEST_F(TestFindWeakNodes, allocator_strategy_with_weak_nodes) {
Expand Down
5 changes: 5 additions & 0 deletions rclcpp/test/rclcpp/test_guard_condition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ class TestGuardCondition : public ::testing::Test
{
rclcpp::init(0, nullptr);
}

static void TearDownTestCase()
{
rclcpp::shutdown();
}
};

/*
Expand Down
5 changes: 5 additions & 0 deletions rclcpp/test/rclcpp/test_node_global_args.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ class TestNodeWithGlobalArgs : public ::testing::Test
const int argc = sizeof(args) / sizeof(const char *);
rclcpp::init(argc, args);
}

static void TearDownTestCase()
{
rclcpp::shutdown();
}
};

TEST_F(TestNodeWithGlobalArgs, local_arguments_before_global) {
Expand Down
5 changes: 5 additions & 0 deletions rclcpp/test/rclcpp/test_parameter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ class TestParameter : public ::testing::Test
{
rclcpp::init(0, nullptr);
}

static void TearDownTestCase()
{
rclcpp::shutdown();
}
};

TEST_F(TestParameter, construct_destruct) {
Expand Down
5 changes: 5 additions & 0 deletions rclcpp/test/rclcpp/test_parameter_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ class TestParameterClient : public ::testing::Test
node_with_option.reset();
}

static void TearDownTestCase()
{
rclcpp::shutdown();
}

// "start_type_description_service" and "use_sim_time"
const uint64_t builtin_param_count = 2;
rclcpp::Node::SharedPtr node;
Expand Down
5 changes: 5 additions & 0 deletions rclcpp/test/rclcpp/test_parameter_event_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ class TestNode : public ::testing::Test
param_handler.reset();
}

static void TearDownTestCase()
{
rclcpp::shutdown();
}

rcl_interfaces::msg::ParameterEvent::SharedPtr same_node_int;
rcl_interfaces::msg::ParameterEvent::SharedPtr same_node_double;
rcl_interfaces::msg::ParameterEvent::SharedPtr diff_node_int;
Expand Down
15 changes: 12 additions & 3 deletions rclcpp/test/rclcpp/test_publisher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ class TestPublisher : public ::testing::Test
public:
static void SetUpTestCase()
{
if (!rclcpp::ok()) {
rclcpp::init(0, nullptr);
}
rclcpp::init(0, nullptr);
}

protected:
Expand All @@ -54,6 +52,11 @@ class TestPublisher : public ::testing::Test
node.reset();
}

static void TearDownTestCase()
{
rclcpp::shutdown();
}

rclcpp::Node::SharedPtr node;
};

Expand Down Expand Up @@ -81,6 +84,7 @@ class TestPublisherSub : public ::testing::Test
protected:
static void SetUpTestCase()
{
rclcpp::init(0, nullptr);
}

void SetUp()
Expand All @@ -94,6 +98,11 @@ class TestPublisherSub : public ::testing::Test
node.reset();
}

static void TearDownTestCase()
{
rclcpp::shutdown();
}

rclcpp::Node::SharedPtr node;
rclcpp::Node::SharedPtr subnode;
};
Expand Down
5 changes: 5 additions & 0 deletions rclcpp/test/rclcpp/test_qos_event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ class TestQosEvent : public ::testing::Test
node.reset();
}

static void TearDownTestCase()
{
rclcpp::shutdown();
}

static constexpr char topic_name[] = "test_topic";
rclcpp::Node::SharedPtr node;
std::function<void(test_msgs::msg::Empty::ConstSharedPtr)> message_callback;
Expand Down
5 changes: 5 additions & 0 deletions rclcpp/test/rclcpp/test_subscription_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ class TestSubscriptionOptions : public ::testing::Test
node.reset();
}

static void TearDownTestCase()
{
rclcpp::shutdown();
}

rclcpp::Node::SharedPtr node;
};

Expand Down
5 changes: 5 additions & 0 deletions rclcpp/test/rclcpp/test_wait_set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ class TestWaitSet : public ::testing::Test
{
rclcpp::init(0, nullptr);
}

static void TearDownTestCase()
{
rclcpp::shutdown();
}
};

/*
Expand Down
5 changes: 5 additions & 0 deletions rclcpp_components/test/test_component_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ class TestComponentManager : public ::testing::Test
{
rclcpp::init(0, nullptr);
}

static void TearDownTestCase()
{
rclcpp::shutdown();
}
};

TEST_F(TestComponentManager, get_component_resources_invalid)
Expand Down
5 changes: 5 additions & 0 deletions rclcpp_components/test/test_component_manager_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ class TestComponentManager : public ::testing::Test
{
rclcpp::init(0, nullptr);
}

static void TearDownTestCase()
{
rclcpp::shutdown();
}
};

// TODO(hidmic): split up tests once Node bring up/tear down races
Expand Down
5 changes: 5 additions & 0 deletions rclcpp_lifecycle/test/test_callback_exceptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ class TestCallbackExceptions : public ::testing::Test
{
rclcpp::init(0, nullptr);
}

static void TearDownTestCase()
{
rclcpp::shutdown();
}
};

class PositiveCallbackExceptionNode : public rclcpp_lifecycle::LifecycleNode
Expand Down
5 changes: 5 additions & 0 deletions rclcpp_lifecycle/test/test_register_custom_callbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ class TestRegisterCustomCallbacks : public ::testing::Test
{
rclcpp::init(0, nullptr);
}

static void TearDownTestCase()
{
rclcpp::shutdown();
}
};

class CustomLifecycleNode : public rclcpp_lifecycle::LifecycleNode
Expand Down
5 changes: 5 additions & 0 deletions rclcpp_lifecycle/test/test_state_machine_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ class TestStateMachineInfo : public ::testing::Test
{
rclcpp::init(0, nullptr);
}

static void TearDownTestCase()
{
rclcpp::shutdown();
}
};

TEST_F(TestStateMachineInfo, available_states) {
Expand Down

0 comments on commit 1f408e3

Please sign in to comment.