Skip to content

Commit

Permalink
Refs #21279: Add example tests
Browse files Browse the repository at this point in the history
Signed-off-by: JesusPoderoso <jesuspoderoso@eprosima.com>
  • Loading branch information
JesusPoderoso committed Jul 15, 2024
1 parent 13e633e commit 7e86516
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 0 deletions.
43 changes: 43 additions & 0 deletions test/examples/static_edp_discovery.compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Copyright 2024 Proyectos y Sistemas de Mantenimiento SL (eProsima).
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
version: "3"

services:
subscriber:
image: @DOCKER_IMAGE_NAME@
volumes:
- @PROJECT_BINARY_DIR@:@PROJECT_BINARY_DIR@
- @fastcdr_LIB_DIR@:@fastcdr_LIB_DIR@
@TINYXML2_LIB_DIR_COMPOSE_VOLUME@
environment:
# TODO(eduponz): LD_LIBRARY_PATH is not the correct variable for Windows
LD_LIBRARY_PATH: @PROJECT_BINARY_DIR@/src/cpp:@fastcdr_LIB_DIR@@TINYXML2_LIB_DIR_COMPOSE_LD_LIBRARY_PATH@
EXAMPLE_DIR: @PROJECT_BINARY_DIR@/examples/cpp/static_edp_discovery@FILE_EXTENSION@
XML_FILE: @PROJECT_BINARY_DIR@/examples/cpp/static_edp_discovery/HelloWorld_static_disc.xml
command: @SHELL_EXECUTABLE@ -c "$${EXAMPLE_DIR}/static_edp_discovery@FILE_EXTENSION@ subscriber --samples 10 --xml $${XML_FILE}"

subscriber-publisher:
image: @DOCKER_IMAGE_NAME@
volumes:
- @PROJECT_BINARY_DIR@:@PROJECT_BINARY_DIR@
- @fastcdr_LIB_DIR@:@fastcdr_LIB_DIR@
@TINYXML2_LIB_DIR_COMPOSE_VOLUME@
environment:
# TODO(eduponz): LD_LIBRARY_PATH is not the correct variable for Windows
LD_LIBRARY_PATH: @PROJECT_BINARY_DIR@/src/cpp:@fastcdr_LIB_DIR@@TINYXML2_LIB_DIR_COMPOSE_LD_LIBRARY_PATH@
EXAMPLE_DIR: @PROJECT_BINARY_DIR@/examples/cpp/static_edp_discovery
XML_FILE: @PROJECT_BINARY_DIR@/examples/cpp/static_edp_discovery/HelloWorld_static_disc.xml
command: @SHELL_EXECUTABLE@ -c "$${EXAMPLE_DIR}/static_edp_discovery@FILE_EXTENSION@ subscriber --samples 10 --xml $${XML_FILE} & $${EXAMPLE_DIR}/static_edp_discovery@FILE_EXTENSION@ publisher --samples 10 --xml $${XML_FILE}"
depends_on:
- subscriber
52 changes: 52 additions & 0 deletions test/examples/test_static_edp_discovery.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Copyright 2024 Proyectos y Sistemas de Mantenimiento SL (eProsima).
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import subprocess

def test_static_edp_discovery():
"""."""
ret = False
out = ''
try:
out = subprocess.check_output(
'@DOCKER_EXECUTABLE@ compose -f static_edp_discovery.compose.yml up',
stderr=subprocess.STDOUT,
shell=True,
timeout=20
).decode().split('\n')

sent = 0
received = 0
for line in out:
if 'SENT' in line:
sent += 1

if 'RECEIVED' in line:
received += 1

if sent != 0 and received != 0 and sent * 2 == received:
ret = True
else:
print('ERROR: sent: ' + str(sent) + ', but received: ' + str(received) +
' (expected: ' + str(sent * 2) + ')')
raise subprocess.CalledProcessError(1, '')

except subprocess.CalledProcessError:
for l in out:
print(l)
except subprocess.TimeoutExpired:
print('TIMEOUT')
print(out)

assert(ret)

0 comments on commit 7e86516

Please sign in to comment.