diff --git a/docker/ros2/Dockerfile b/docker/ros2/Dockerfile index 92c8acd..fe3cdf6 100644 --- a/docker/ros2/Dockerfile +++ b/docker/ros2/Dockerfile @@ -8,7 +8,8 @@ RUN apt-get update && apt-get install -y \ ros-${ROS_DISTRO}-rosbridge-suite \ # ros-${ROS_DISTRO}-tf2-web-republisher \ # ros-${ROS_DISTRO}-ros-tutorials \ - # ros-${ROS_DISTRO}-actionlib-tutorials \ + ros-${ROS_DISTRO}-examples-rclpy-minimal-action-server \ + ros-${ROS_DISTRO}-example-interfaces \ --no-install-recommends \ # Clear apt-cache to reduce image size && rm -rf /var/lib/apt/lists/* diff --git a/docker/ros2/integration-tests.launch b/docker/ros2/integration-tests.launch index 1aedc6d..0ae4f79 100644 --- a/docker/ros2/integration-tests.launch +++ b/docker/ros2/integration-tests.launch @@ -1,4 +1,7 @@ - - + + + + + diff --git a/tests/ros2/test_actions_client.py b/tests/ros2/test_actions_client.py new file mode 100644 index 0000000..2acffad --- /dev/null +++ b/tests/ros2/test_actions_client.py @@ -0,0 +1,67 @@ +from __future__ import print_function + +import time + +import pytest + +from roslibpy import Ros, ActionGoal +from roslibpy.actionlib import ActionClient + +# @pytest.fixture +# def action_client(): +# ros = Ros(host="localhost", port=9090) +# ros.run() + +# return ActionClient( +# ros, +# "/fibonacci", +# "custom_action_interfaces/action/Fibonacci" +# ) + + +def feedback_callback(msg): + print(f"Action feedback: {msg['partial_sequence']}") + + +def test_action_success(): + + ros = Ros(host="localhost", port=9090) + ros.run() + + action_client = ActionClient(ros, "/fibonacci", "example_interfaces/action/Fibonacci") + + result = None + + def result_feedback(msg): + result = msg + + action_client.send_goal(ActionGoal({"order": 8}), result_feedback, feedback_callback) + + while result is None: + time.sleep(1) + + assert result["status"] == "success" + assert result["values"]["sequence"][-1] == 21 + + +def test_action_cancellation(): + + ros = Ros(host="localhost", port=9090) + ros.run() + + action_client = ActionClient(ros, "/fibonacci", "example_interfaces/action/Fibonacci") + + result = None + + goal_id = action_client.send_goal( + ActionGoal({"order": 8}), None, feedback_callback, lambda msg: print(f"Action failed with message: {msg}") + ) + time.sleep(3) + print("Sending action goal cancel request...") + action_client.cancel_goal(goal_id) + + while result is None: + time.sleep(1) + + assert result["status"] == "cancelled" + assert result["values"]