Skip to content

Commit

Permalink
Refs #20650: 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 May 27, 2024
1 parent 66bbd2d commit a803fdc
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 0 deletions.
34 changes: 34 additions & 0 deletions test/examples/delivery_mechanisms.compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# FASTDDS_TODO_BEFORE(3, 0, "This compose file should be used for the future configuration example");
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/delivery_mechanisms
SUBSCRIBER_ADDITIONAL_ARGUMENTS: ${SUB_ARGS}
network_mode: host
ipc: host
command: @SHELL_EXECUTABLE@ -c "$${EXAMPLE_DIR}/delivery_mechanisms@FILE_EXTENSION@ subscriber --samples 10 $${SUBSCRIBER_ADDITIONAL_ARGUMENTS}"

publisher-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/delivery_mechanisms
PUBLISHER_ADDITIONAL_ARGUMENTS: ${PUB_ARGS}
SUBSCRIBER_ADDITIONAL_ARGUMENTS: ${SUB_ARGS}
network_mode: host
ipc: host
command: @SHELL_EXECUTABLE@ -c "$${EXAMPLE_DIR}/delivery_mechanisms@FILE_EXTENSION@ subscriber --samples 10 $${SUBSCRIBER_ADDITIONAL_ARGUMENTS} & $${EXAMPLE_DIR}/delivery_mechanisms@FILE_EXTENSION@ pubsub --samples 10 $${PUBLISHER_ADDITIONAL_ARGUMENTS}"
80 changes: 80 additions & 0 deletions test/examples/test_examples.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""."""
import subprocess
import pytest

def test_basic_configuration():
"""."""
Expand Down Expand Up @@ -78,3 +79,82 @@ def test_hello_world():
print(out)

assert(ret)

delivery_test_cases = [
('--mechanism shm', '--mechanism shm', 3),
('--mechanism shm --ignore-local-endpoints', '--mechanism shm', 2),
('--mechanism udp', '--mechanism udp', 3),
('--mechanism udp --ignore-local-endpoints', '--mechanism udp', 2),
('--mechanism tcp', '--mechanism tcp', 3),
('--mechanism tcp --ignore-local-endpoints', '--mechanism tcp', 2),
('--mechanism data-sharing', '--mechanism data-sharing', 3),
('--mechanism data-sharing --ignore-local-endpoints', '--mechanism data-sharing', 2),
('--mechanism intra-process', '--unknown-argument', 1) # force subscribers to fail
]

@pytest.mark.parametrize("pub_args, sub_args, repetitions", delivery_test_cases)
def test_delivery_mechanisms(pub_args, sub_args, repetitions):
"""."""
ret = False
out = ''

command_prerequisites = 'PUB_ARGS="' + pub_args + '" SUB_ARGS="' + sub_args + '" '
try:
out = subprocess.check_output(command_prerequisites + '@DOCKER_EXECUTABLE@ compose -f delivery_mechanisms.compose.yml up',
stderr=subprocess.STDOUT,
shell=True,
timeout=60 # TCP requires higher timeout
).decode().split('\n')

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

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

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

delivery_timeout_test_cases = [
('--mechanism shm --ignore-local-endpoints', '--mechanism udp'),
('--mechanism shm --ignore-local-endpoints', '--mechanism tcp'),
('--mechanism udp --ignore-local-endpoints', '--mechanism tcp'),
('--mechanism udp --ignore-local-endpoints', '--mechanism data-sharing'),
('--mechanism tcp --ignore-local-endpoints', '--mechanism data-sharing'),
('--mechanism intra-process --ignore-local-endpoints', '--unknown-argument') # force subscribers to fail
]

@pytest.mark.parametrize("pub_args, sub_args", delivery_timeout_test_cases)
def test_delivery_mechanisms_timeout(pub_args, sub_args):
"""."""
ret = False
out = ''

command_prerequisites = 'PUB_ARGS="' + pub_args + '" SUB_ARGS="' + sub_args + '" '
try:
out = subprocess.check_output(command_prerequisites + '@DOCKER_EXECUTABLE@ compose -f delivery_mechanisms.compose.yml up',
stderr=subprocess.STDOUT,
shell=True,
timeout=5
)
except subprocess.CalledProcessError as e:
print (e.output)
except subprocess.TimeoutExpired:
ret = True

assert(ret)

0 comments on commit a803fdc

Please sign in to comment.