Skip to content

Commit 8374b3a

Browse files
jparisursanchez15
andauthored
Docker Compose Tests (#262)
* Create Dockerfile and compose for WAN testing scenarios Signed-off-by: RaulSanchez <raul@eprosima.com> * Build Docker image Signed-off-by: RaulSanchez <raul@eprosima.com> * Add test launch file Signed-off-by: RaulSanchez <raul@eprosima.com> * Update docker compose with timeout argument and github inputs Signed-off-by: RaulSanchez <raul@eprosima.com> * Add python validator for subscribers Signed-off-by: RaulSanchez <raul@eprosima.com> * Run compose tests with ctest Signed-off-by: RaulSanchez <raul@eprosima.com> * Add docker compose TCP test Signed-off-by: RaulSanchez <raul@eprosima.com> * Add more documentation and apply review suggestions Signed-off-by: RaulSanchez <raul@eprosima.com> * Change python script name Signed-off-by: RaulSanchez <raul@eprosima.com> * Move compose tests to separate project Signed-off-by: RaulSanchez <raul@eprosima.com> * apply own suggestions and making some changes Signed-off-by: jparisu <javierparis@eprosima.com> * Add UDP and DiscServer tests Signed-off-by: jparisu <javierparis@eprosima.com> * compose ci only execute test of ddsrouter_test Signed-off-by: jparisu <javierparis@eprosima.com> * apply suggestions Signed-off-by: jparisu <javierparis@eprosima.com> Signed-off-by: RaulSanchez <raul@eprosima.com> Signed-off-by: jparisu <javierparis@eprosima.com> Co-authored-by: RaulSanchez <raul@eprosima.com>
1 parent 36c96d8 commit 8374b3a

33 files changed

Lines changed: 1375 additions & 16 deletions

.github/docker/Dockerfile

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
FROM ubuntu:20.04
2+
LABEL author=raul@eprosima.com
3+
4+
# Avoid interactuation with installation of some package that needs the locale.
5+
ENV TZ=Europe/Madrid
6+
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
7+
8+
# Avoids using interactions during building
9+
ENV DEBIAN_FRONTEND=noninteractive
10+
11+
# Use a bash shell so it is possigle to run things like `source` (required for colcon builds)
12+
SHELL ["/bin/bash", "-c"]
13+
14+
# Install apt dependencies
15+
RUN apt-get update && apt-get install --yes --no-install-recommends \
16+
git \
17+
build-essential \
18+
cmake \
19+
python3-pip \
20+
wget \
21+
software-properties-common \
22+
zip \
23+
python3 \
24+
gradle \
25+
openjdk-8-jdk \
26+
libssl-dev \
27+
libasio-dev \
28+
libtinyxml2-dev \
29+
openssl \
30+
libyaml-cpp-dev
31+
32+
# Install required python modules
33+
RUN pip3 install \
34+
colcon-common-extensions \
35+
colcon-mixin \
36+
lxml \
37+
vcstool \
38+
GitPython \
39+
pyyaml \
40+
jsonschema
41+
42+
WORKDIR /ddsrouter
43+
44+
ARG ddsrouter_branch=main
45+
ARG fastdds_branch=master
46+
47+
RUN mkdir src && \
48+
wget https://raw.githubusercontent.com/eProsima/DDS-Router/${ddsrouter_branch}/ddsrouter.repos && \
49+
vcs import src < ddsrouter.repos && \
50+
cd src/ddsrouter && git checkout ${ddsrouter_branch} && cd ../.. && \
51+
cd src/fastdds && git checkout ${fastdds_branch} && cd ../.. && \
52+
cp -r src/fastdds/examples/cpp/dds/BasicConfigurationExample src/. && \
53+
colcon build --event-handlers console_direct+ --cmake-args -DLOG_INFO=ON
54+
55+
COPY run.bash /root/run.bash
56+
57+
RUN chmod +x /root/run.bash
58+
59+
ENTRYPOINT ["/root/run.bash" ]

.github/docker/run.bash

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
3+
# Setup environment
4+
source "/ddsrouter/install/setup.bash"
5+
6+
exec "$@"

.github/workflows/docker_test.yml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
name: docker_test
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
fastdds_branch:
7+
description: 'Branch or tag of Fast DDS repository (https://github.com/eProsima/Fast-DDS)'
8+
required: true
9+
default: 'master'
10+
ddsrouter_branch:
11+
description: 'Branch or tag of DDS Router repository (https://github.com/eProsima/DDS-Router)'
12+
required: true
13+
default: 'main'
14+
pull_request:
15+
push:
16+
branches:
17+
- main
18+
schedule:
19+
- cron: '0 0 * * *'
20+
21+
jobs:
22+
docker_test:
23+
runs-on: ubuntu-20.04
24+
env:
25+
DEFAULT_FASTDDS_BRANCH: 'master'
26+
DEFAULT_DDSROUTER_BRANCH: 'main'
27+
DDSROUTER_COMPOSE_TEST_DOCKER_IMAGE: "ddsrouter:ci"
28+
steps:
29+
- name: Sync eProsima/DDS-Router repository
30+
uses: actions/checkout@v2
31+
with:
32+
path: src/DDS-Router
33+
34+
# Install colcon and required packages
35+
- name: Install apt packages
36+
uses: ./src/DDS-Router/.github/actions/install-apt-packages
37+
38+
- name: Install Python packages
39+
uses: ./src/DDS-Router/.github/actions/install-python-packages
40+
41+
- name: Build DDS Router Docker image
42+
run: |
43+
cd src/DDS-Router/.github/docker
44+
docker build \
45+
--no-cache \
46+
--build-arg fastdds_branch=${{ github.event.inputs.fastdds_branch || env.DEFAULT_FASTDDS_BRANCH }} \
47+
--build-arg ddsrouter_branch=${{ github.event.inputs.ddsrouter_branch || env.DEFAULT_DDSROUTER_BRANCH }} \
48+
-t ${{ env.DDSROUTER_COMPOSE_TEST_DOCKER_IMAGE }} \
49+
-f Dockerfile .
50+
51+
- name: Check if Docker image exists
52+
run: |
53+
[ -n "$(docker images -q ${{ env.DDSROUTER_COMPOSE_TEST_DOCKER_IMAGE }})" ] || echo "DDS Router Docker image does not exists"
54+
55+
- name: Run tests
56+
run: |
57+
export DDSROUTER_COMPOSE_TEST_DOCKER_IMAGE=${{ env.DDSROUTER_COMPOSE_TEST_DOCKER_IMAGE }}
58+
colcon build --event-handlers console_direct+ --packages-up-to ddsrouter_test --cmake-args -DBUILD_COMPOSE_TESTS=ON
59+
colcon test \
60+
--packages-select ddsrouter_test \
61+
--event-handlers console_direct+ \
62+
--return-code-on-test-failure \
63+
--ctest-args \
64+
--label-exclude xfail \
65+
--timeout 60

ddsrouter_cmake/cmake/compilation/compile_test.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,4 @@ macro(compile_test_tool _TEST_PATH)
7272

7373
endif()
7474

75-
endmacro()
75+
endmacro()

ddsrouter_cmake/cmake/project/cmake_options.cmake

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,20 @@
2222
#
2323
# CMAKE OPTIONS ALLOWED
2424
#
25-
# - BUILD_TESTS : OFF
26-
# - BUILD_DOCS_TESTS : BUILD_TESTS
27-
# - BUILD_TOOL_TESTS : BUILD_TESTS
28-
# - BUILD_LIBRARY_TESTS : BUILD_TESTS
25+
# - BUILD_TESTS : OFF
26+
# - BUILD_DOCS_TESTS : BUILD_TESTS
27+
# - BUILD_TOOL_TESTS : BUILD_TESTS
28+
# - BUILD_LIBRARY_TESTS : BUILD_TESTS
2929
#
30-
# - BUILD_ALL : BUILD_TESTS
31-
# - BUILD_DOCS : BUILD_DOCS_TESTS
32-
# - BUILD_TOOL : ON
33-
# - BUILD_LIBRARY : ON
30+
# - BUILD_ALL : BUILD_TESTS
31+
# - BUILD_DOCS : BUILD_DOCS_TESTS
32+
# - BUILD_TOOL : ON
33+
# - BUILD_LIBRARY : ON
3434
#
35-
# - CODE_COVERAGE : OFF
36-
# - CMAKE_BUILD_TYPE : Release
35+
# - CODE_COVERAGE : OFF
36+
# - CMAKE_BUILD_TYPE : Release
3737
#
38-
# - LOG_INFO : OFF // TODO change LOG cmake options to make them smarter
38+
# - LOG_INFO : OFF // TODO change LOG cmake options to make them smarter
3939
#
4040
# ARGUMENTS:
4141
# NONE

ddsrouter_cmake/cmake/project/load_project_settings.cmake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ macro(load_project_settings)
9595
set (MODULE_THIRDPARTY_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../thirdparty")
9696
endif()
9797

98+
# Set MODULE_FIND_PACKAGES
99+
if (NOT MODULE_FIND_PACKAGES)
100+
set (MODULE_FIND_PACKAGES "")
101+
endif()
102+
98103
# Set MODULE_DEPENDENCIES
99104
if (NOT MODULE_DEPENDENCIES)
100105
set (MODULE_DEPENDENCIES ${MODULE_FIND_PACKAGES})

ddsrouter_core/src/cpp/core/DDSRouterImpl.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -317,11 +317,11 @@ void DDSRouterImpl::init_participants_()
317317
}
318318

319319
// If DDS Router has not two or more Participants configured, it should fail
320-
if (participants_database_->size() < 2)
320+
if (participants_database_->size() < 1)
321321
{
322-
logError(DDSROUTER, "At least two Participants are required to initialize a DDS Router.");
322+
logError(DDSROUTER, "At least a Participant is required to initialize a DDS Router.");
323323
throw utils::InitializationException(utils::Formatter()
324-
<< "DDS Router requires at least 2 Participants to start.");
324+
<< "DDS Router requires at least 1 Participant to start.");
325325
}
326326
}
327327

ddsrouter_test/CMakeLists.txt

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Copyright 2022 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
###############################################################################
16+
# CMake build rules for DDS Router Submodule
17+
###############################################################################
18+
cmake_minimum_required(VERSION 3.5)
19+
20+
###############################################################################
21+
# Find package ddsrouter_cmake
22+
###############################################################################
23+
# Package ddsrouter_cmake is required to get every cmake macro needed
24+
find_package(ddsrouter_cmake REQUIRED)
25+
26+
###############################################################################
27+
# Project
28+
###############################################################################
29+
# Configure project by info set in project_settings.cmake
30+
# - Load project_settings variables
31+
# - Read version
32+
# - Set installation paths
33+
configure_project()
34+
35+
# Call explictly project
36+
project(
37+
${MODULE_NAME}
38+
VERSION
39+
${MODULE_VERSION}
40+
DESCRIPTION
41+
${MODULE_DESCRIPTION}
42+
)
43+
44+
###############################################################################
45+
# Test
46+
###############################################################################
47+
# Compile tests if CMake options requires it
48+
option(BUILD_COMPOSE_TESTS "Compile compose tests" OFF)
49+
50+
if(BUILD_COMPOSE_TESTS)
51+
message(STATUS "Compiling Compose Tests of ${PROJECT_NAME}")
52+
configure_test_flags()
53+
test_requirements()
54+
add_subdirectory(compose)
55+
endif()
56+
# NOTE: this is done explicitly and not by a CMake macro (compile_test) as other packages
57+
# because it does not feel like reusable, so adding it to ddsrouter_cmake does not seems appropiate.
58+
59+
###############################################################################
60+
# Packaging
61+
###############################################################################
62+
# NOTE: No packaging needed for this package as it is test only. However it removes the colcon warning.
63+
# Install package
64+
eprosima_packaging()

ddsrouter_test/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# eProsima DDS Router Test Module
2+
3+
This module builds a test suite for the DDS Router.
4+
5+
## CMake Options
6+
7+
If CMake option `BUILD_COMPOSE_TESTS` is not active, this package will build nothing.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Copyright 2022 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# Name of files to test
16+
set(TESTS
17+
repeater
18+
tcp
19+
udp
20+
discovery_server
21+
)
22+
23+
foreach(TEST ${TESTS})
24+
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/${TEST} DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
25+
endforeach()
26+
27+
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/docker-compose.sh
28+
${CMAKE_CURRENT_BINARY_DIR}/docker-compose.sh
29+
COPYONLY)
30+
31+
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/execute_and_validate_subscriber.py
32+
${CMAKE_CURRENT_BINARY_DIR}/execute_and_validate_subscriber.py
33+
COPYONLY)
34+
35+
find_program (BASH_PROGRAM bash)
36+
37+
# Populate the tests
38+
foreach(TEST IN LISTS TESTS)
39+
40+
set(TEST_NAME "tool.application.ddsrouter.compose.${TEST}")
41+
42+
message(STATUS "Building test ${TEST_NAME}")
43+
44+
add_test(
45+
NAME ${TEST_NAME}
46+
COMMAND ${BASH_PROGRAM} ${CMAKE_CURRENT_BINARY_DIR}/docker-compose.sh
47+
-t ${TEST_NAME}
48+
-f ${CMAKE_CURRENT_BINARY_DIR}/${TEST}/compose.yml)
49+
50+
endforeach()

0 commit comments

Comments
 (0)