Repository: AutonoLab/pteranodon (language: python)

Issue:
Integration Tests 
Integration tests only pass right now


Discussion / hints:

Fix patch:
diff --git a/.ci/Dockerfile b/.ci/Dockerfile
new file mode 100644
index 00000000..a92043b7
--- /dev/null
+++ b/.ci/Dockerfile
@@ -0,0 +1,31 @@
+# Tests Dockerfile
+
+FROM ubuntu:20.04
+
+ARG GIT_REF_NAME
+
+ENV WORKSPACE_DIR /root
+ENV PTERANODON_DIR ${WORKSPACE_DIR}/pteranodon
+
+# Add docker-compose-wait tool -------------------
+#ENV WAIT_VERSION 2.7.2
+#ADD https://github.com/ufoscout/docker-compose-wait/releases/download/$WAIT_VERSION/wait /wait
+#RUN chmod +x /wait
+
+# Install deps
+RUN apt-get update && \
+    apt-get install -y curl git python3-pip netcat&& \
+    apt-get -y autoremove && \
+    apt-get clean autoclean && \
+    rm -rf /var/lib/apt/lists/{apt,dpkg,cache,log} /tmp/* /var/tmp/*
+
+# Checkout current version of pteranodon
+RUN git clone https://github.com/AutonoLab/pteranodon.git ${PTERANODON_DIR}
+RUN echo "REF ${GIT_REF_NAME}"
+RUN git -C ${PTERANODON_DIR} checkout "${GIT_REF_NAME}"
+RUN git -C ${PTERANODON_DIR} submodule update --init --recursive # Future proofing
+
+RUN pip3 install -r ${PTERANODON_DIR}/requirements.txt
+RUN pip3 install -r ${PTERANODON_DIR}/requirements-test.txt
+
+WORKDIR "${PTERANODON_DIR}"
diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile
index 59477653..3d956248 100644
--- a/.devcontainer/Dockerfile
+++ b/.devcontainer/Dockerfile
@@ -71,4 +71,5 @@ COPY sitl_rtsp_proxy ${SITL_RTSP_PROXY}
 RUN cmake -B${SITL_RTSP_PROXY}/build -H${SITL_RTSP_PROXY}
 RUN cmake --build ${SITL_RTSP_PROXY}/build
 
+
 ENTRYPOINT ["/root/entrypoint.sh"]


Test patch:
diff --git a/.ci/tests-docker-compose.yaml b/.ci/tests-docker-compose.yaml
new file mode 100644
index 00000000..c17920ee
--- /dev/null
+++ b/.ci/tests-docker-compose.yaml
@@ -0,0 +1,59 @@
+# Adapted from: https://github.com/AeroRust/mav/blob/main/docker-compose.yml
+version: '3.8'
+
+services:
+  px4-gazebo-headless:
+    image: jonasvautherin/px4-gazebo-headless:latest
+    container_name: px4-gazebo-headless
+    environment:
+      - NO_PXH=1
+      - VERBOSE=1
+      - VERBOSE_SIM=1
+    ports:
+      # for MAVLINK API/Offboard and MAVSDK
+      - "14540-14549:14540-14549"
+      # for MAVLINK QGroundControl
+      - "14550:14550"
+      # simulator
+      - "4560:4560"
+      # For Video Stream
+      # try the RTSP port https://github.com/JonasVautherin/px4-gazebo-headless/blob/master/sitl_rtsp_proxy/main.cpp#L12
+      - "8554:8554"
+      # try default UDP Gazebo port https://dev.px4.io/master/en/simulation/gazebo.html#video-streaming
+      - "5600:5600/udp"
+      # default gazebo port for conecting with client
+      - "11345:11345"
+    networks:
+      internal-ip:
+          ipv4_address: 172.20.0.5
+      internal:
+      external:
+    stdin_open: true
+    tty: true
+    command: 172.20.0.6 # The IP address of the pteranodon tests
+  test:
+    depends_on:
+      - px4-gazebo-headless
+    build: .
+    container_name: test
+    ports:
+      - "4000:4000"
+    networks:
+      internal-ip:
+          ipv4_address: 172.20.0.6
+      internal:
+      external:
+    stdin_open: true
+    tty: true
+
+networks:
+  internal:
+    internal: true
+  external:
+  internal-ip:
+    driver: bridge
+    ipam:
+      driver: default
+      config:
+      - subnet: 172.20.0.0/24
+      
\ No newline at end of file
diff --git a/.github/workflows/integration-tests.yaml b/.github/workflows/integration-tests.yaml
index 7d1c808f..bba24e23 100644
--- a/.github/workflows/integration-tests.yaml
+++ b/.github/workflows/integration-tests.yaml
@@ -10,19 +10,28 @@ on:
 jobs:
   offboard:
     name: "Test Offboard"
-
     runs-on: ubuntu-latest
+    env:
+      BRANCH_REF: "${{ github.event.pull_request.head.ref }}"
 
     steps:
       - uses: actions/checkout@v1
-      - name: Setup Dependencies
+      - name: Build Docker Containers
+        run: |
+          docker compose -f .ci/tests-docker-compose.yaml -p tests-services build --build-arg GIT_REF_NAME="$BRANCH_REF"
+      - name: Run Docker Containers
         run: |
-          python -m pip install --upgrade pip
-          pip install -r requirements.txt
-          pip install -r requirements-test.txt
+          docker compose -f .ci/tests-docker-compose.yaml -p tests-services up -d --wait
+          sleep 30s
       - name: Test Abstract Plugin
         run: |
-           echo "Skipped"
+          docker compose -f .ci/tests-docker-compose.yaml -p tests-services exec -T test pytest --log-cli-level=INFO --full-trace -rP tests/integration/test_offboard.py
+
+          
+          
+
+# docker network inspect -v tests-services_default
+# pytest --log-cli-level=INFO --full-trace -rP integration/test_offboard.py --hostname=tests-services_px4_docker_1
 #          pytest --log-cli-level=INFO --full-trace -rP tests/integration/test_offboard.py --hostname=px4_docker
 #    services:
 #      px4_docker:
diff --git a/tests/integration/conftest.py b/tests/conftest.py
similarity index 55%
rename from tests/integration/conftest.py
rename to tests/conftest.py
index b044e4e4..fc8db694 100644
--- a/tests/integration/conftest.py
+++ b/tests/conftest.py
@@ -8,8 +8,19 @@ def pytest_addoption(parser: pytest.Parser):
         default="",
         help="Hostname for MAV SDK server, default is none",
     )
+    parser.addoption(
+        "--port",
+        action="store",
+        default=14540,
+        help="Port for MAV SDK server, default is 14540",
+    )
 
 
 @pytest.fixture(scope="session")
 def hostname(request: pytest.FixtureRequest):
     return request.config.getoption("--hostname")
+
+
+@pytest.fixture(scope="session")
+def port(request: pytest.FixtureRequest):
+    return request.config.getoption("--port")
diff --git a/tests/integration/test_offboard.py b/tests/integration/test_offboard.py
index a87d9dc3..08a1daf3 100644
--- a/tests/integration/test_offboard.py
+++ b/tests/integration/test_offboard.py
@@ -5,21 +5,23 @@
 
 from .helpers import PluginTaskFetcher
 from pteranodon.simple_drone import SimpleDrone
+from pteranodon.utils import ServerDetector
 from pteranodon.plugins.base_plugins import Offboard
 from threading import Condition
 
 # To run docker container:
 # docker run --rm -it jonasvautherin/px4-gazebo-headless:1.13.0
 
-# To run tests
+# To run testsg
 # pytest --log-cli-level=INFO --full-trace -rP tests/integration/test_offboard.py
 
 
 @pytest.fixture(scope="session")
-def test_drone(hostname) -> SimpleDrone:
+def test_drone(hostname, port) -> SimpleDrone:
     # Setup
     print("Setup")
-    test_drone = SimpleDrone(f"udp://{hostname}:14540")
+    print(f"Host: {hostname}, Port: {port}")
+    test_drone = SimpleDrone(f"udp://{hostname}:{port}")
 
     yield test_drone
 
@@ -35,7 +37,9 @@ def test_start(test_drone):
 
     task_fetcher = PluginTaskFetcher(offboard_plugin)
 
-    test_drone.put((offboard_plugin.start, task_fetcher.trigger))
+    start_cmd = SimpleDrone.Command(offboard_plugin.start, handler=task_fetcher.trigger)
+
+    test_drone.put(start_cmd)
 
     start_task = task_fetcher.fetch(5.0)
 
@@ -57,7 +61,9 @@ def test_hold(test_drone):
 
     task_fetcher = PluginTaskFetcher(offboard_plugin)
 
-    test_drone.put((offboard_plugin.hold, task_fetcher.trigger))
+    hold_cmd = SimpleDrone.Command(offboard_plugin.hold, handler=task_fetcher.trigger)
+
+    test_drone.put(hold_cmd)
 
     hold_task = task_fetcher.fetch(5.0)