Skip to content

Commit

Permalink
Add test case for cancel thread termination
Browse files Browse the repository at this point in the history
  • Loading branch information
robin-mueller committed Dec 25, 2024
1 parent ff11f10 commit d10e732
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion pyrobosim/test/core/test_robot.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,11 +568,19 @@ def test_execute_action_cancel(self, caplog):
)

# Start a thread that cancels the actions mid execution.
threading.Timer(1.0, robot.cancel_actions).start()
cancel_thread = threading.Timer(1.0, robot.cancel_actions)
cancel_thread.start()

# Run action and check that it failed due to being canceled.
result = robot.execute_action(action)
assert result.status == ExecutionStatus.CANCELED

# We want to make sure the cancellation thread is finished
# (cancel_actions has returned).
# Consequently, we must give the thread some time to detect the
# correct lifetime status
time.sleep(0.1)
assert not cancel_thread.is_alive()

# Retry the action, which should now succeed.
assert robot.execute_action(action).is_success()
Expand Down

0 comments on commit d10e732

Please sign in to comment.