Skip to content

Commit

Permalink
Add ROS2 to CI and add a small test for it
Browse files Browse the repository at this point in the history
  • Loading branch information
gonzalocasas committed Apr 17, 2024
1 parent 22af997 commit d53271d
Show file tree
Hide file tree
Showing 13 changed files with 217 additions and 7 deletions.
59 changes: 59 additions & 0 deletions .github/workflows/build-ros1.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: build

on:
push:
branches:
- main
tags:
- 'v*'
pull_request:
branches:
- main

jobs:
build-cpython:
runs-on: ${{ matrix.os }}
strategy:
matrix:
name: [
"ubuntu-py39",
"ubuntu-py310",
"ubuntu-py311",
]
include:
- name: "ubuntu-py39"
os: ubuntu-latest
python-version: "3.9"
- name: "ubuntu-py310"
os: ubuntu-latest
python-version: "3.10"
- name: "ubuntu-py311"
os: ubuntu-latest
python-version: "3.11"
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install wheel
- name: Install
run: |
python -m pip install --no-cache-dir -r requirements-dev.txt
- name: Set up docker containers
run: |
docker build -t gramaziokohler/rosbridge:integration_tests_ros1 ./docker/ros1
docker run -d -p 9090:9090 --name rosbridge gramaziokohler/rosbridge:integration_tests_ros1 /bin/bash -c "roslaunch /integration-tests.launch"
docker ps -a
- name: Run linter
run: |
invoke check
- name: Run tests
run: |
pytest tests/ros1
- name: Tear down docker containers
run: |
docker rm -f rosbridge
59 changes: 59 additions & 0 deletions .github/workflows/build-ros2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: build

on:
push:
branches:
- main
tags:
- 'v*'
pull_request:
branches:
- main

jobs:
build-cpython:
runs-on: ${{ matrix.os }}
strategy:
matrix:
name: [
"ubuntu-py39",
"ubuntu-py310",
"ubuntu-py311",
]
include:
- name: "ubuntu-py39"
os: ubuntu-latest
python-version: "3.9"
- name: "ubuntu-py310"
os: ubuntu-latest
python-version: "3.10"
- name: "ubuntu-py311"
os: ubuntu-latest
python-version: "3.11"
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install wheel
- name: Install
run: |
python -m pip install --no-cache-dir -r requirements-dev.txt
- name: Set up docker containers
run: |
docker build -t gramaziokohler/rosbridge:integration_tests_ros2 ./docker/ros2
docker run -d -p 9090:9090 --name rosbridge gramaziokohler/rosbridge:integration_tests_ros2 /bin/bash -c "ros2 launch /integration-tests.launch"
docker ps -a
- name: Run linter
run: |
invoke check
- name: Run tests
run: |
pytest tests/ros2
- name: Tear down docker containers
run: |
docker rm -f rosbridge
6 changes: 3 additions & 3 deletions docker/ros2/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ SHELL ["/bin/bash","-c"]
# Install rosbridge
RUN apt-get update && apt-get install -y \
ros-iron-rosbridge-suite \
ros-iron-tf2-web-republisher \
ros-iron-ros-tutorials \
ros-iron-actionlib-tutorials \
# ros-iron-tf2-web-republisher \
# ros-iron-ros-tutorials \
# ros-iron-actionlib-tutorials \
--no-install-recommends \
# Clear apt-cache to reduce image size
&& rm -rf /var/lib/apt/lists/*
Expand Down
4 changes: 1 addition & 3 deletions docker/ros2/integration-tests.launch
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<launch>
<include file="$(find-pkg-share rosbridge_server)/launch/rosbridge_websocket_launch.xml">
<arg name="port" value="9092"/>
</include>
<include file="$(find-pkg-share rosbridge_server)/launch/rosbridge_websocket_launch.xml" />
<!-- <node pkg="tf2_web_republisher" type="tf2_web_republisher" name="tf2_web_republisher"></node> -->
</launch>
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion tests/test_topic.py → tests/ros1/test_topic.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def receive_message(message):
context["wait"].set()

def start_sending():
for i in range(3):
for _ in range(3):
msg = dict(header=Header(stamp=Time.now(), frame_id="base"), point=dict(x=0.0, y=1.0, z=2.0))
publisher.publish(Message(msg))
time.sleep(0.1)
Expand Down
94 changes: 94 additions & 0 deletions tests/ros2/test_topic_ros2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
from __future__ import print_function

import threading
import time

from roslibpy import Message, Ros, Time, Topic
from roslibpy.ros2 import Header


def test_topic_pubsub():
context = dict(wait=threading.Event(), counter=0)

ros = Ros("127.0.0.1", 9090)
ros.run()

listener = Topic(ros, "/chatter", "std_msgs/String")
publisher = Topic(ros, "/chatter", "std_msgs/String")

def receive_message(message):
context["counter"] += 1
assert message["data"] == "hello world", "Unexpected message content"

if context["counter"] == 3:
listener.unsubscribe()
context["wait"].set()

def start_sending():
while True:
if context["counter"] >= 3:
break
publisher.publish(Message({"data": "hello world"}))
time.sleep(0.1)
publisher.unadvertise()

def start_receiving():
listener.subscribe(receive_message)

t1 = threading.Thread(target=start_receiving)
t2 = threading.Thread(target=start_sending)

t1.start()
t2.start()

if not context["wait"].wait(10):
raise Exception

t1.join()
t2.join()

assert context["counter"] >= 3, "Expected at least 3 messages but got " + str(context["counter"])
ros.close()


def test_topic_with_header():
context = dict(wait=threading.Event())

ros = Ros("127.0.0.1", 9090)
ros.run()

listener = Topic(ros, "/points", "geometry_msgs/PointStamped")
publisher = Topic(ros, "/points", "geometry_msgs/PointStamped")

def receive_message(message):
assert message["header"]["frame_id"] == "base"
assert message["point"]["x"] == 0.0
assert message["point"]["y"] == 1.0
assert message["point"]["z"] == 2.0
listener.unsubscribe()
context["wait"].set()

def start_sending():
for _ in range(3):
msg = dict(header=Header(stamp=Time.now(), frame_id="base"), point=dict(x=0.0, y=1.0, z=2.0))
publisher.publish(Message(msg))
time.sleep(0.1)

publisher.unadvertise()

def start_receiving():
listener.subscribe(receive_message)

t1 = threading.Thread(target=start_receiving)
t2 = threading.Thread(target=start_sending)

t1.start()
t2.start()

if not context["wait"].wait(10):
raise Exception

t1.join()
t2.join()

ros.close()

0 comments on commit d53271d

Please sign in to comment.