Skip to content

Commit 9d2e196

Browse files
authored
Fix the teardown of the controller tests (#2183)
1 parent 665c60c commit 9d2e196

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

diff_drive_controller/test/test_diff_drive_controller.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,15 @@ class TestDiffDriveController : public ::testing::Test
100100
controller_name + "/cmd_vel", rclcpp::SystemDefaultsQoS());
101101
}
102102

103+
void TearDown() override
104+
{
105+
// Reset the controller before the fixture is destroyed to ensure the controller's
106+
// shutdown transition (which clears loaned interfaces) runs while the underlying
107+
// StateInterface/CommandInterface objects are still alive. LoanedStateInterface stores
108+
// a const reference (not a shared_ptr), so destruction order matters.
109+
controller_.reset();
110+
}
111+
103112
static void TearDownTestCase() { rclcpp::shutdown(); }
104113

105114
/// Publish velocity msgs

omni_wheel_drive_controller/test/test_omni_wheel_drive_controller.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,15 @@ class OmniWheelDriveControllerFixture : public ::testing::Test
9898
"/test_omni_wheel_drive_controller/cmd_vel", rclcpp::SystemDefaultsQoS());
9999
}
100100

101+
void TearDown() override
102+
{
103+
// Reset the controller before the fixture is destroyed to ensure the controller's
104+
// shutdown transition (which clears loaned interfaces) runs while the underlying
105+
// StateInterface/CommandInterface objects are still alive. LoanedStateInterface stores
106+
// a const reference (not a shared_ptr), so destruction order matters.
107+
controller_.reset();
108+
}
109+
101110
static void TearDownTestCase() { rclcpp::shutdown(); }
102111

103112
protected:

0 commit comments

Comments
 (0)