Skip to content

Commit

Permalink
Reject goals processed by malformed goal callbacks
Browse files Browse the repository at this point in the history
Signed-off-by: Jacob Perron <jacob@openrobotics.org>
  • Loading branch information
jacobperron committed Feb 13, 2019
1 parent 3c5c172 commit b0589c4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
6 changes: 5 additions & 1 deletion rclpy/rclpy/action/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,11 @@ async def _execute_goal_request(self, request_header_and_message):
if not goal_id_exists:
# Call user goal callback
response = await await_or_execute(self._goal_callback, goal_request)
accepted = GoalResponse.ACCEPT == response
if not isinstance(response, GoalResponse):
self._node.get_logger().warn(
'Goal request callback did not return a GoalResponse type. Rejecting goal.')
else:
accepted = GoalResponse.ACCEPT == response

if accepted:
# Create a goal handle
Expand Down
22 changes: 22 additions & 0 deletions rclpy/test/action/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,28 @@ def handle_accepted_callback(goal_handle):
self.assertFalse(future.result().accepted)
action_server.destroy()

def test_goal_callback_invalid_return(self):

def goal_callback(goal):
return 'Invalid return type'

action_server = ActionServer(
self.node,
Fibonacci,
'fibonacci',
execute_callback=self.execute_goal_callback,
goal_callback=goal_callback,
handle_accepted_callback=lambda gh: None,
)

goal_msg = Fibonacci.Goal()
goal_msg.action_goal_id = UUID(uuid=list(uuid.uuid4().bytes))
future = self.mock_action_client.send_goal(goal_msg)
rclpy.spin_until_future_complete(self.node, future, self.executor)
# An invalid return type in the goal callback should translate to a rejected goal
self.assertFalse(future.result().accepted)
action_server.destroy()

def test_multi_goal_accept(self):
executor = MultiThreadedExecutor(context=self.context)
action_server = ActionServer(
Expand Down

0 comments on commit b0589c4

Please sign in to comment.