Skip to content

Commit edd5db3

Browse files
authored
Fix the teardown of the controller tests (backport #2183) (#2186)
1 parent 5fdd616 commit edd5db3

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
@@ -101,6 +101,15 @@ class TestDiffDriveController : public ::testing::Test
101101
controller_name + "/cmd_vel", rclcpp::SystemDefaultsQoS());
102102
}
103103

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

106115
/// 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
@@ -99,6 +99,15 @@ class OmniWheelDriveControllerFixture : public ::testing::Test
9999
"/test_omni_wheel_drive_controller/cmd_vel", rclcpp::SystemDefaultsQoS());
100100
}
101101

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

104113
protected:

0 commit comments

Comments
 (0)