Skip to content

Commit

Permalink
Back to cancel_as_success=False but make cancel of indefinite wait to…
Browse files Browse the repository at this point in the history
… report success.

Signed-off-by: Joni Pöllänen <joni.pollanen@karelics.fi>
  • Loading branch information
jonipol committed Sep 12, 2024
1 parent c2f1c6f commit c412b2c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
7 changes: 5 additions & 2 deletions task_manager/task_manager/tasks/system_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,10 @@ def _execute_cb(self, goal_handle: ServerGoalHandle) -> Wait.Result:

while rclpy.ok() and self._node.get_clock().now() < end_time:
if goal_handle.is_cancel_requested:
goal_handle.canceled()
if duration_in_seconds <= 0.0:
goal_handle.succeed()
else:
goal_handle.canceled()
return Wait.Result()

if not goal_handle.is_active:
Expand Down Expand Up @@ -194,7 +197,7 @@ def get_task_specs(topic: str) -> TaskSpecs:
blocking=True,
cancel_on_stop=True,
topic=topic,
cancel_reported_as_success=True,
cancel_reported_as_success=False,
reentrant=False,
msg_interface=Wait,
task_server_type=TaskServerType.ACTION,
Expand Down
6 changes: 2 additions & 4 deletions task_manager/test/integration_tests/test_system_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,7 @@ def test_wait_task(self) -> None:
wait_result = goal_handle.get_result()

self.assertEqual(cancel_response.status, GoalStatus.STATUS_SUCCEEDED)
# If the task would not stay waiting, the status would be DONE
self.assertEqual(wait_result.result.task_status, TaskStatus.CANCELED)
self.assertEqual(wait_result.result.task_status, TaskStatus.DONE)
self.assertEqual(wait_result.result.task_result, json.dumps({}))

with self.subTest("Input duration is zero - Wait indefinitely"):
Expand All @@ -141,8 +140,7 @@ def test_wait_task(self) -> None:
wait_result = goal_handle.get_result()

self.assertEqual(cancel_response.status, GoalStatus.STATUS_SUCCEEDED)
# If the task would not stay waiting with duration 0.0, the status would be DONE
self.assertEqual(wait_result.result.task_status, TaskStatus.CANCELED)
self.assertEqual(wait_result.result.task_status, TaskStatus.DONE)
self.assertEqual(wait_result.result.task_result, json.dumps({}))


Expand Down

0 comments on commit c412b2c

Please sign in to comment.