Add return code to CancelGoal service response (#710)
* Populate return code of CancelGoal service response Signed-off-by: Jacob Perron <jacob@openrobotics.org> * Throw if there is an error processing a cancel goal request Signed-off-by: Jacob Perron <jacob@openrobotics.org> * Make cancel callback signature consistent across cancel methods and add tests Refactored the callback signature for canceling one goal. Now it is the same as the other cancel methods. This makes it easier to communicate the error code to the user. Signed-off-by: Jacob Perron <jacob@openrobotics.org> * Address review Signed-off-by: Jacob Perron <jacob@openrobotics.org>
This commit is contained in:
		
							parent
							
								
									7ed130cf7a
								
							
						
					
					
						commit
						ecf35114b6
					
				
					 4 changed files with 165 additions and 38 deletions
				
			
		| 
						 | 
				
			
			@ -464,8 +464,8 @@ TEST_F(TestClient, async_cancel_one_goal)
 | 
			
		|||
 | 
			
		||||
  auto future_cancel = action_client->async_cancel_goal(goal_handle);
 | 
			
		||||
  dual_spin_until_future_complete(future_cancel);
 | 
			
		||||
  bool goal_canceled = future_cancel.get();
 | 
			
		||||
  EXPECT_TRUE(goal_canceled);
 | 
			
		||||
  ActionCancelGoalResponse::SharedPtr cancel_response = future_cancel.get();
 | 
			
		||||
  EXPECT_EQ(ActionCancelGoalResponse::ERROR_NONE, cancel_response->return_code);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
TEST_F(TestClient, async_cancel_one_goal_with_callback)
 | 
			
		||||
| 
						 | 
				
			
			@ -484,18 +484,21 @@ TEST_F(TestClient, async_cancel_one_goal_with_callback)
 | 
			
		|||
  auto future_cancel = action_client->async_cancel_goal(
 | 
			
		||||
    goal_handle,
 | 
			
		||||
    [&cancel_response_received, goal_handle](
 | 
			
		||||
      typename ActionGoalHandle::SharedPtr goal_handle_canceled, bool cancel_accepted) mutable
 | 
			
		||||
      ActionCancelGoalResponse::SharedPtr response) mutable
 | 
			
		||||
    {
 | 
			
		||||
      if (
 | 
			
		||||
        goal_handle_canceled->get_goal_id() == goal_handle->get_goal_id() &&
 | 
			
		||||
        cancel_accepted)
 | 
			
		||||
        ActionCancelGoalResponse::ERROR_NONE == response->return_code &&
 | 
			
		||||
        1ul == response->goals_canceling.size() &&
 | 
			
		||||
        goal_handle->get_goal_id() == response->goals_canceling[0].goal_id.uuid)
 | 
			
		||||
      {
 | 
			
		||||
        cancel_response_received = true;
 | 
			
		||||
      }
 | 
			
		||||
    });
 | 
			
		||||
  dual_spin_until_future_complete(future_cancel);
 | 
			
		||||
  bool goal_canceled = future_cancel.get();
 | 
			
		||||
  EXPECT_TRUE(goal_canceled);
 | 
			
		||||
  auto cancel_response = future_cancel.get();
 | 
			
		||||
  EXPECT_EQ(ActionCancelGoalResponse::ERROR_NONE, cancel_response->return_code);
 | 
			
		||||
  ASSERT_EQ(1ul, cancel_response->goals_canceling.size());
 | 
			
		||||
  EXPECT_EQ(goal_handle->get_goal_id(), cancel_response->goals_canceling[0].goal_id.uuid);
 | 
			
		||||
  EXPECT_TRUE(cancel_response_received);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -527,6 +530,7 @@ TEST_F(TestClient, async_cancel_all_goals)
 | 
			
		|||
  dual_spin_until_future_complete(future_cancel_all);
 | 
			
		||||
  auto cancel_response = future_cancel_all.get();
 | 
			
		||||
 | 
			
		||||
  EXPECT_EQ(ActionCancelGoalResponse::ERROR_NONE, cancel_response->return_code);
 | 
			
		||||
  ASSERT_EQ(2ul, cancel_response->goals_canceling.size());
 | 
			
		||||
  EXPECT_EQ(goal_handle0->get_goal_id(), cancel_response->goals_canceling[0].goal_id.uuid);
 | 
			
		||||
  EXPECT_EQ(goal_handle1->get_goal_id(), cancel_response->goals_canceling[1].goal_id.uuid);
 | 
			
		||||
| 
						 | 
				
			
			@ -575,6 +579,7 @@ TEST_F(TestClient, async_cancel_all_goals_with_callback)
 | 
			
		|||
  dual_spin_until_future_complete(future_cancel_all);
 | 
			
		||||
  auto cancel_response = future_cancel_all.get();
 | 
			
		||||
 | 
			
		||||
  EXPECT_EQ(ActionCancelGoalResponse::ERROR_NONE, cancel_response->return_code);
 | 
			
		||||
  EXPECT_TRUE(cancel_callback_received);
 | 
			
		||||
  ASSERT_EQ(2ul, cancel_response->goals_canceling.size());
 | 
			
		||||
  EXPECT_EQ(goal_handle0->get_goal_id(), cancel_response->goals_canceling[0].goal_id.uuid);
 | 
			
		||||
| 
						 | 
				
			
			@ -608,6 +613,7 @@ TEST_F(TestClient, async_cancel_some_goals)
 | 
			
		|||
  dual_spin_until_future_complete(future_cancel_some);
 | 
			
		||||
  auto cancel_response = future_cancel_some.get();
 | 
			
		||||
 | 
			
		||||
  EXPECT_EQ(ActionCancelGoalResponse::ERROR_NONE, cancel_response->return_code);
 | 
			
		||||
  ASSERT_EQ(1ul, cancel_response->goals_canceling.size());
 | 
			
		||||
  EXPECT_EQ(goal_handle0->get_goal_id(), cancel_response->goals_canceling[0].goal_id.uuid);
 | 
			
		||||
  EXPECT_EQ(rclcpp_action::GoalStatus::STATUS_CANCELED, goal_handle0->get_status());
 | 
			
		||||
| 
						 | 
				
			
			@ -649,6 +655,7 @@ TEST_F(TestClient, async_cancel_some_goals_with_callback)
 | 
			
		|||
  dual_spin_until_future_complete(future_cancel_some);
 | 
			
		||||
  auto cancel_response = future_cancel_some.get();
 | 
			
		||||
 | 
			
		||||
  EXPECT_EQ(ActionCancelGoalResponse::ERROR_NONE, cancel_response->return_code);
 | 
			
		||||
  EXPECT_TRUE(cancel_callback_received);
 | 
			
		||||
  ASSERT_EQ(1ul, cancel_response->goals_canceling.size());
 | 
			
		||||
  EXPECT_EQ(goal_handle0->get_goal_id(), cancel_response->goals_canceling[0].goal_id.uuid);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue