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 unload of controllers when spawned with --unload-on-kill (backport #1717) #1842

Merged
merged 1 commit into from
Nov 3, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
29 changes: 21 additions & 8 deletions controller_manager/controller_manager/spawner.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def main(args=None):

node.get_logger().info(
bcolors.OKGREEN
+ "Configured and activated all the parsed controllers list!"
+ f"Configured and activated all the parsed controllers list : {controller_names}!"
+ bcolors.ENDC
)
if args.stopped:
Expand All @@ -265,20 +265,33 @@ def main(args=None):
node, controller_manager_name, controller_names, [], True, True, 5.0
)
if not ret.ok:
node.get_logger().error("Failed to deactivate controller")
node.get_logger().error(
bcolors.FAIL + "Failed to deactivate controller" + bcolors.ENDC
)
return 1

node.get_logger().info("Deactivated controller")
node.get_logger().info(
f"Successfully deactivated controllers : {controller_names}"
)

elif args.stopped:
node.get_logger().warn('"--stopped" flag is deprecated use "--inactive" instead')

ret = unload_controller(node, controller_manager_name, controller_name)
if not ret.ok:
node.get_logger().error("Failed to unload controller")
return 1
unload_status = True
for controller_name in controller_names:
ret = unload_controller(node, controller_manager_name, controller_name)
if not ret.ok:
unload_status = False
node.get_logger().error(
bcolors.FAIL
+ f"Failed to unload controller : {controller_name}"
+ bcolors.ENDC
)

node.get_logger().info("Unloaded controller")
if unload_status:
node.get_logger().info(f"Successfully unloaded controllers : {controller_names}")
else:
return 1
return 0
except KeyboardInterrupt:
pass
Expand Down
19 changes: 19 additions & 0 deletions controller_manager/test/test_spawner_unspawner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,25 @@ TEST_F(TestLoadController, unload_on_kill)
ASSERT_EQ(cm_->get_loaded_controllers().size(), 0ul);
}

TEST_F(TestLoadController, unload_on_kill_activate_as_group)
{
// Launch spawner with unload on kill
// timeout command will kill it after the specified time with signal SIGINT
ControllerManagerRunner cm_runner(this);
cm_->set_parameter(rclcpp::Parameter("ctrl_3.type", test_controller::TEST_CONTROLLER_CLASS_NAME));
cm_->set_parameter(rclcpp::Parameter("ctrl_2.type", test_controller::TEST_CONTROLLER_CLASS_NAME));
std::stringstream ss;
ss << "timeout --signal=INT 5 "
<< std::string(coveragepy_script) +
" $(ros2 pkg prefix controller_manager)/lib/controller_manager/spawner "
<< "ctrl_3 ctrl_2 --activate-as-group -c test_controller_manager --unload-on-kill";

EXPECT_NE(std::system(ss.str().c_str()), 0)
<< "timeout should have killed spawner and returned non 0 code";

ASSERT_EQ(cm_->get_loaded_controllers().size(), 0ul);
}

TEST_F(TestLoadController, spawner_with_many_controllers)
{
std::stringstream ss;
Expand Down
Loading