[SOLVED] [ROS2 humble linux] Wait until a node has been destroyed in launch_testing
Hello. This is what I am trying to do:
- Create a lifecycle-managed C++ node using launch_testing
- Perform a test on the node
- Stop the node
- Wait until the node has been destroyed
- Exit the test
My question is: how would you approach problem 4.?
Here is what I came up with:
inside the node under test:
LifecycleNodeInterface::CallbackReturn on_shutdown(const rclcpp_lifecycle::State& state) { RCLCPP_INFO(get_logger(), "on shutdown() is called from state %s.", state.label().c_str()); std::raise(SIGINT); return LifecycleNode::on_shutdown(state); }
inside the test routine:
proc_info.assertWaitForShutdown(process=node, timeout=60)
This is working somehow but it is ugly as hell. Why should I manually raise SIGINT just to destroy a node?
I have tried to use theTRANSITION_DESTROY
but run into this bug.
Asked by LastStarDust on 2023-03-31 05:30:53 UTC
Answers
I solved the problem by adding this action to the launch description:
destroy_node = RegisterEventHandler(
OnStateTransition(
target_lifecycle_node=node,
start_state="shuttingdown",
goal_state="finalized",
entities=[
EmitEvent(event=ShutdownProcess(process_matcher=matches_action(node))),
],
)
)
Asked by LastStarDust on 2023-03-31 08:22:16 UTC
Comments