Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix LifecycleNode in tests #1470

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,13 @@ class AckermannSteeringControllerFixture : public ::testing::Test
"/test_ackermann_steering_controller/reference", rclcpp::SystemDefaultsQoS());
}

static void TearDownTestCase() {}
void TearDown()
{
controller_->get_node()->shutdown();
controller_.reset(nullptr); // this calls the dtor, but does not call shutdown transition
}

void TearDown() { controller_.reset(nullptr); }
static void TearDownTestCase() {}

protected:
void SetUpController(const std::string controller_name = "test_ackermann_steering_controller")
Expand Down
9 changes: 5 additions & 4 deletions admittance_controller/test/test_admittance_controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,14 @@ class AdmittanceControllerTest : public ::testing::Test
test_broadcaster_node_ = std::make_shared<rclcpp::Node>("test_broadcaster_node");
}

static void TearDownTestCase()
static void TearDownTestCase() {}

void TearDown()
{
// rclcpp::shutdown();
controller_->get_node()->shutdown();
controller_.reset(nullptr); // this calls the dtor, but does not call shutdown transition
}

void TearDown() { controller_.reset(nullptr); }

protected:
controller_interface::return_type SetUpController(
const std::string & controller_name, const std::vector<rclcpp::Parameter> & parameter_overrides)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,13 @@ class BicycleSteeringControllerFixture : public ::testing::Test
"/test_bicycle_steering_controller/reference", rclcpp::SystemDefaultsQoS());
}

static void TearDownTestCase() {}
void TearDown()
{
controller_->get_node()->shutdown();
controller_.reset(nullptr); // this calls the dtor, but does not call shutdown transition
}

void TearDown() { controller_.reset(nullptr); }
static void TearDownTestCase() {}

protected:
void SetUpController(const std::string controller_name = "test_bicycle_steering_controller")
Expand Down
12 changes: 10 additions & 2 deletions diff_drive_controller/test/test_diff_drive_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ class TestableDiffDriveController : public diff_drive_controller::DiffDriveContr
class TestDiffDriveController : public ::testing::Test
{
protected:
void SetUp() override
static void SetUpTestCase() {}

void SetUp()
{
// use the name of the test as the controller name (i.e, the node name) to be able to set
// parameters from yaml for each test
Expand All @@ -97,7 +99,13 @@ class TestDiffDriveController : public ::testing::Test
controller_name + "/cmd_vel", rclcpp::SystemDefaultsQoS());
}

static void TearDownTestCase() { rclcpp::shutdown(); }
void TearDown()
{
controller_->get_node()->shutdown();
controller_.reset(nullptr); // this calls the dtor, but does not call shutdown transition
}

static void TearDownTestCase() {}

/// Publish velocity msgs
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ void JointGroupEffortControllerTest::SetUp()
controller_ = std::make_unique<FriendJointGroupEffortController>();
}

void JointGroupEffortControllerTest::TearDown() { controller_.reset(nullptr); }
void JointGroupEffortControllerTest::TearDown()
{
controller_->get_node()->shutdown();
controller_.reset(nullptr); // this calls the dtor, but does not call shutdown transition
}

void JointGroupEffortControllerTest::SetUpController()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ void ForceTorqueSensorBroadcasterTest::SetUp()
fts_broadcaster_ = std::make_unique<FriendForceTorqueSensorBroadcaster>();
}

void ForceTorqueSensorBroadcasterTest::TearDown() { fts_broadcaster_.reset(nullptr); }
void ForceTorqueSensorBroadcasterTest::TearDown()
{
fts_broadcaster_->get_node()->shutdown();
fts_broadcaster_.reset(nullptr); // this calls the dtor, but does not call shutdown transition
}

void ForceTorqueSensorBroadcasterTest::SetUpFTSBroadcaster()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ void ForwardCommandControllerTest::SetUp()
controller_ = std::make_unique<FriendForwardCommandController>();
}

void ForwardCommandControllerTest::TearDown() { controller_.reset(nullptr); }
void ForwardCommandControllerTest::TearDown()
{
controller_->get_node()->shutdown();
controller_.reset(nullptr); // this calls the dtor, but does not call shutdown transition
}

void ForwardCommandControllerTest::SetUpController()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ void MultiInterfaceForwardCommandControllerTest::SetUp()
controller_ = std::make_unique<FriendMultiInterfaceForwardCommandController>();
}

void MultiInterfaceForwardCommandControllerTest::TearDown() { controller_.reset(nullptr); }
void MultiInterfaceForwardCommandControllerTest::TearDown()
{
controller_->get_node()->shutdown();
controller_.reset(nullptr); // this calls the dtor, but does not call shutdown transition
}

void MultiInterfaceForwardCommandControllerTest::SetUpController(bool set_params_and_activate)
{
Expand Down
3 changes: 2 additions & 1 deletion gripper_controllers/test/test_gripper_controllers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ void GripperControllerTest<T>::SetUp()
template <typename T>
void GripperControllerTest<T>::TearDown()
{
controller_.reset(nullptr);
controller_->get_node()->shutdown();
controller_.reset(nullptr); // this calls the dtor, but does not call shutdown transition
}

template <typename T>
Expand Down
6 changes: 5 additions & 1 deletion imu_sensor_broadcaster/test/test_imu_sensor_broadcaster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ void IMUSensorBroadcasterTest::SetUp()
imu_broadcaster_ = std::make_unique<FriendIMUSensorBroadcaster>();
}

void IMUSensorBroadcasterTest::TearDown() { imu_broadcaster_.reset(nullptr); }
void IMUSensorBroadcasterTest::TearDown()
{
imu_broadcaster_->get_node()->shutdown();
imu_broadcaster_.reset(nullptr); // this calls the dtor, but does not call shutdown transition
}

void IMUSensorBroadcasterTest::SetUpIMUBroadcaster()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ void JointStateBroadcasterTest::SetUp()
state_broadcaster_ = std::make_unique<FriendJointStateBroadcaster>();
}

void JointStateBroadcasterTest::TearDown() { state_broadcaster_.reset(nullptr); }
void JointStateBroadcasterTest::TearDown()
{
state_broadcaster_->get_node()->shutdown();
state_broadcaster_.reset(nullptr); // this calls the dtor, but does not call shutdown transition
}

void JointStateBroadcasterTest::SetUpStateBroadcaster(
const std::vector<std::string> & joint_names, const std::vector<std::string> & interfaces)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ class TrajectoryControllerTest : public ::testing::Test
traj_controller_->get_node()->deactivate().id(),
lifecycle_msgs::msg::State::PRIMARY_STATE_INACTIVE);
}
traj_controller_->get_node()->shutdown();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,14 @@ class MecanumDriveControllerFixture : public ::testing::Test
tf_odom_s_publisher_ = tf_odom_s_publisher_node_->create_publisher<TfStateMsg>(
"/test_mecanum_drive_controller/tf_odometry", rclcpp::SystemDefaultsQoS());
}
void TearDown()
{
controller_->get_node()->shutdown();
controller_.reset(nullptr); // this calls the dtor, but does not call shutdown transition
}

static void TearDownTestCase() {}

void TearDown() { controller_.reset(nullptr); }

protected:
void SetUpController(const std::string controller_name = "test_mecanum_drive_controller")
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ void GripperControllerTest::SetUp()
controller_ = std::make_unique<FriendGripperController>();
}

void GripperControllerTest::TearDown() { controller_.reset(nullptr); }
void GripperControllerTest::TearDown()
{
controller_->get_node()->shutdown();
controller_.reset(nullptr); // this calls the dtor, but does not call shutdown transition
}

void GripperControllerTest::SetUpController(
const std::string & controller_name = "test_gripper_action_position_controller",
Expand Down
8 changes: 6 additions & 2 deletions pid_controller/test/test_pid_controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,13 @@ class PidControllerFixture : public ::testing::Test
"/test_pid_controller/set_feedforward_control");
}

static void TearDownTestCase() { rclcpp::shutdown(); }
void TearDown()
{
controller_->get_node()->shutdown();
controller_.reset(nullptr); // this calls the dtor, but does not call shutdown transition
}

void TearDown() { controller_.reset(nullptr); }
static void TearDownTestCase() {}

protected:
void SetUpController(const std::string controller_name = "test_pid_controller")
Expand Down
6 changes: 5 additions & 1 deletion pose_broadcaster/test/test_pose_broadcaster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ using hardware_interface::LoanedStateInterface;

void PoseBroadcasterTest::SetUp() { pose_broadcaster_ = std::make_unique<PoseBroadcaster>(); }

void PoseBroadcasterTest::TearDown() { pose_broadcaster_.reset(nullptr); }
void PoseBroadcasterTest::TearDown()
{
pose_broadcaster_->get_node()->shutdown();
pose_broadcaster_.reset(nullptr); // this calls the dtor, but does not call shutdown transition
}

void PoseBroadcasterTest::SetUpPoseBroadcaster()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ void JointGroupPositionControllerTest::SetUp()
controller_ = std::make_unique<FriendJointGroupPositionController>();
}

void JointGroupPositionControllerTest::TearDown() { controller_.reset(nullptr); }
void JointGroupPositionControllerTest::TearDown()
{
controller_->get_node()->shutdown();
controller_.reset(nullptr); // this calls the dtor, but does not call shutdown transition
}

void JointGroupPositionControllerTest::SetUpController()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ void RangeSensorBroadcasterTest::SetUp()
range_broadcaster_ = std::make_unique<range_sensor_broadcaster::RangeSensorBroadcaster>();
}

void RangeSensorBroadcasterTest::TearDown() { range_broadcaster_.reset(nullptr); }
void RangeSensorBroadcasterTest::TearDown()
{
range_broadcaster_->get_node()->shutdown();
range_broadcaster_.reset(nullptr); // this calls the dtor, but does not call shutdown transition
}

controller_interface::return_type RangeSensorBroadcasterTest::init_broadcaster(
std::string broadcaster_name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,13 @@ class SteeringControllersLibraryFixture : public ::testing::Test
"/test_steering_controllers_library/reference", rclcpp::SystemDefaultsQoS());
}

static void TearDownTestCase() {}
void TearDown()
{
controller_->get_node()->shutdown();
controller_.reset(nullptr); // this calls the dtor, but does not call shutdown transition
}

void TearDown() { controller_.reset(nullptr); }
static void TearDownTestCase() {}

protected:
void SetUpController(const std::string controller_name = "test_steering_controllers_library")
Expand Down
8 changes: 7 additions & 1 deletion tricycle_controller/test/test_tricycle_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,20 @@ class TestTricycleController : public ::testing::Test
protected:
static void SetUpTestCase() { rclcpp::init(0, nullptr); }

void SetUp() override
void SetUp()
{
controller_ = std::make_unique<TestableTricycleController>();
pub_node = std::make_shared<rclcpp::Node>("velocity_publisher");
velocity_publisher = pub_node->create_publisher<geometry_msgs::msg::TwistStamped>(
controller_name + "/cmd_vel", rclcpp::SystemDefaultsQoS());
}

void TearDown()
{
controller_->get_node()->shutdown();
controller_.reset(nullptr); // this calls the dtor, but does not call shutdown transition
}

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

/// Publish velocity msgs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,13 @@ class TricycleSteeringControllerFixture : public ::testing::Test
"/test_tricycle_steering_controller/reference", rclcpp::SystemDefaultsQoS());
}

static void TearDownTestCase() {}
void TearDown()
{
controller_->get_node()->shutdown();
controller_.reset(nullptr); // this calls the dtor, but does not call shutdown transition
}

void TearDown() { controller_.reset(nullptr); }
static void TearDownTestCase() {}

protected:
void SetUpController(const std::string controller_name = "test_tricycle_steering_controller")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ void JointGroupVelocityControllerTest::SetUp()
controller_ = std::make_unique<FriendJointGroupVelocityController>();
}

void JointGroupVelocityControllerTest::TearDown() { controller_.reset(nullptr); }
void JointGroupVelocityControllerTest::TearDown()
{
controller_->get_node()->shutdown();
controller_.reset(nullptr); // this calls the dtor, but does not call shutdown transition
}

void JointGroupVelocityControllerTest::SetUpController()
{
Expand Down
Loading