Skip to content
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
9 changes: 8 additions & 1 deletion rclcpp_action/include/rclcpp_action/server_goal_handle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,20 @@ class ServerGoalHandle : public ServerGoalHandleBase
* If execution of a goal is deferred then `ServerGoalHandle::set_executing()` must be called
* first.
*
* \throws std::runtime_error If the goal is in any state besides executing.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i was going to honor this original design behavior, but this could be a bit surprising for user application. so this PR only prints the warning that instead.

* If the goal is in any state besides executing, a warning will be logged and the feedback
* will not be published.
*
* \param[in] feedback_msg the message to publish to clients.
*/
void
publish_feedback(std::shared_ptr<typename ActionT::Feedback> feedback_msg)
{
if (!is_executing()) {
RCLCPP_WARN(
rclcpp::get_logger("rclcpp_action"),
"publish_feedback() called on a goal handle not in executing state, ignoring");
return;
}
auto feedback_message = std::make_shared<typename ActionT::Impl::FeedbackMessage>();
feedback_message->goal_id.uuid = uuid_;
feedback_message->feedback = *feedback_msg;
Expand Down
22 changes: 22 additions & 0 deletions rclcpp_action/test/test_server_goal_handle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,28 @@ TEST_F(TestServerGoalHandle, execute) {
EXPECT_THROW(handle_->execute(), rclcpp::exceptions::RCLError);
}

TEST_F(TestServerGoalHandle, publish_feedback_not_executing) {
// Goal is in accepted (not executing) state, publish_feedback should warn and ignore
auto feedback = std::make_shared<test_msgs::action::Fibonacci::Feedback>();
EXPECT_NO_THROW(handle_->publish_feedback(feedback));
}

TEST_F(TestServerGoalHandle, publish_feedback_executing) {
// Goal is in executing state, publish_feedback should succeed
handle_->execute();
auto feedback = std::make_shared<test_msgs::action::Fibonacci::Feedback>();
EXPECT_NO_THROW(handle_->publish_feedback(feedback));
}

TEST_F(TestServerGoalHandle, publish_feedback_after_succeed) {
// Goal reached terminal state, publish_feedback should warn and ignore
handle_->execute();
auto result = std::make_shared<test_msgs::action::Fibonacci::Result>();
handle_->succeed(result);
auto feedback = std::make_shared<test_msgs::action::Fibonacci::Feedback>();
EXPECT_NO_THROW(handle_->publish_feedback(feedback));
}

TEST_F(TestServerGoalHandle, rcl_action_goal_handle_get_status_error) {
auto mock = mocking_utils::patch_and_return(
"lib:rclcpp_action", rcl_action_goal_handle_get_status, RCL_RET_ERROR);
Expand Down