Skip to content

Commit cb28826

Browse files
committed
Add test cases for receive_status_before_service_response.
Signed-off-by: Tony <[email protected]>
1 parent aae375b commit cb28826

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

rclcpp_action/test/test_client.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,38 @@ TEST_F(TestClientAgainstServer, async_send_goal_no_callbacks)
429429
EXPECT_FALSE(goal_handle->is_result_aware());
430430
}
431431

432+
TEST_F(TestClientAgainstServer, receive_status_before_service_response)
433+
{
434+
auto action_client = rclcpp_action::create_client<ActionType>(client_node, action_name);
435+
ASSERT_TRUE(action_client->wait_for_action_server(WAIT_FOR_SERVER_TIMEOUT));
436+
437+
ActionGoal good_goal;
438+
good_goal.order = 5;
439+
auto future_goal_handle = action_client->async_send_goal(good_goal);
440+
// Spin the client, to send out the goals
441+
client_executor.spin_some();
442+
// Spin the server until a goal is received
443+
while (goals.empty()) {
444+
server_executor.spin_once();
445+
}
446+
// Set the goals to an executing state
447+
ActionStatusMessage status_message;
448+
for (const auto & [goal_uuid, goal] : goals) {
449+
rclcpp_action::GoalStatus goal_status;
450+
goal_status.goal_info.goal_id.uuid = goal.first->goal_id.uuid;
451+
goal_status.goal_info.stamp = goal.second->stamp;
452+
goal_status.status = rclcpp_action::GoalStatus::STATUS_EXECUTING;
453+
status_message.status_list.push_back(goal_status);
454+
}
455+
status_publisher->publish(status_message);
456+
// Spin until the client receives the goal
457+
dual_spin_until_future_complete(future_goal_handle);
458+
auto goal_handle = future_goal_handle.get();
459+
EXPECT_EQ(rclcpp_action::GoalStatus::STATUS_EXECUTING, goal_handle->get_status());
460+
EXPECT_FALSE(goal_handle->is_feedback_aware());
461+
EXPECT_FALSE(goal_handle->is_result_aware());
462+
}
463+
432464
TEST_F(TestClientAgainstServer, bad_goal_handles)
433465
{
434466
auto action_client0 = rclcpp_action::create_client<ActionType>(client_node, action_name);

rclcpp_action/test/test_generic_client.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,42 @@ TEST_F(TestGenericClientAgainstServer, async_send_goal_no_callbacks)
468468
EXPECT_FALSE(goal_handle->is_result_aware());
469469
}
470470

471+
TEST_F(TestGenericClientAgainstServer, receive_status_before_service_response)
472+
{
473+
auto action_generic_client = rclcpp_action::create_generic_client(
474+
client_node,
475+
action_name,
476+
"test_msgs/action/Fibonacci");
477+
ASSERT_TRUE(action_generic_client->wait_for_action_server(WAIT_FOR_SERVER_TIMEOUT));
478+
479+
ActionGoal good_goal;
480+
good_goal.order = 5;
481+
auto future_goal_handle =
482+
action_generic_client->async_send_goal(&good_goal, sizeof(good_goal));
483+
// Spin the client, to send out the goals
484+
client_executor.spin_some();
485+
// Spin the server until a goal is received
486+
while (goals.empty()) {
487+
server_executor.spin_once();
488+
}
489+
// Set the goals to an executing state
490+
ActionStatusMessage status_message;
491+
for (const auto & [goal_uuid, goal] : goals) {
492+
rclcpp_action::GoalStatus goal_status;
493+
goal_status.goal_info.goal_id.uuid = goal.first->goal_id.uuid;
494+
goal_status.goal_info.stamp = goal.second->stamp;
495+
goal_status.status = rclcpp_action::GoalStatus::STATUS_EXECUTING;
496+
status_message.status_list.push_back(goal_status);
497+
}
498+
status_publisher->publish(status_message);
499+
// Spin until the client receives the goal
500+
dual_spin_until_future_complete(future_goal_handle);
501+
auto goal_handle = future_goal_handle.get();
502+
EXPECT_EQ(rclcpp_action::GoalStatus::STATUS_EXECUTING, goal_handle->get_status());
503+
EXPECT_FALSE(goal_handle->is_feedback_aware());
504+
EXPECT_FALSE(goal_handle->is_result_aware());
505+
}
506+
471507
TEST_F(TestGenericClientAgainstServer, async_send_goal_request_no_callbacks)
472508
{
473509
auto action_generic_client = rclcpp_action::create_generic_client(

0 commit comments

Comments
 (0)