Skip to content

Commit

Permalink
Refs #20650: Include publisher tests
Browse files Browse the repository at this point in the history
Signed-off-by: JesusPoderoso <[email protected]>
  • Loading branch information
JesusPoderoso committed Jun 17, 2024
1 parent e5b63bd commit 4434cb0
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 26 deletions.
17 changes: 16 additions & 1 deletion test/examples/delivery_mechanisms.compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,19 @@ services:
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}"
command: @SHELL_EXECUTABLE@ -c "$${EXAMPLE_DIR}/delivery_mechanisms@FILE_EXTENSION@ publisher --samples 10 $${PUBLISHER_ADDITIONAL_ARGUMENTS} & $${EXAMPLE_DIR}/delivery_mechanisms@FILE_EXTENSION@ subscriber --samples 10 $${SUBSCRIBER_ADDITIONAL_ARGUMENTS}"

pubsub:
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
PUBSUB_ADDITIONAL_ARGUMENTS: ${PUBSUB_ARGS}
network_mode: host
ipc: host
command: @SHELL_EXECUTABLE@ -c "$${EXAMPLE_DIR}/delivery_mechanisms@FILE_EXTENSION@ pubsub --samples 10 $${PUBSUB_ADDITIONAL_ARGUMENTS}"
56 changes: 31 additions & 25 deletions test/examples/test_delivery_mechanisms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,34 @@
import pytest

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),
# tcp takes longer to match, so expect much more samples in this case
('--mechanism tcp --ignore-local-endpoints -s 250', '--mechanism tcp -s 250', 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
('', '', '--unknown-command', 2),
('--unknown-command', '', '', 3),
('--unknown-command', '', ' --ignore-local-endpoints', 2),
('--mechanism shm', '--mechanism shm', '--unknown-command', 2),
('--unknown-command', '--mechanism shm', '--mechanism shm', 3),
('--unknown-command', '--mechanism shm', '--mechanism shm --ignore-local-endpoints', 2),
('--mechanism udp', '--mechanism udp', '--unknown-command', 2),
('--unknown-command', '--mechanism udp', '--mechanism udp', 3),
('--unknown-command', '--mechanism udp', '--mechanism udp --ignore-local-endpoints', 2),
# tcp takes longer to match, so explicitly expect much more samples in this case
# Note: pubsub with TCP and ignore-local-endpoints NOT set is not supported, tested in below tests
('--mechanism tcp -s 220', '--mechanism tcp -s 220', '--unknown-command', 2),
('--unknown-command', '--mechanism tcp -s 220', '--mechanism tcp -s 220 --ignore-local-endpoints', 2),
('--mechanism data-sharing', '--mechanism data-sharing', '--unknown-command', 2),
('--unknown-command', '--mechanism data-sharing', '--mechanism data-sharing', 3),
('--unknown-command', '--mechanism data-sharing', '--mechanism data-sharing --ignore-local-endpoints', 2),
# # Intra-process only makes sense for pubsub entities. This test forces entities != pubsub to fail, so
# # only 1 message is expected per sample (the local one)
('--unknown-argument', '--unknown-argument', '--mechanism intra-process', 1)
]

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

command_prerequisites = 'PUB_ARGS="' + pub_args + '" SUB_ARGS="' + sub_args + '" '
command_prerequisites = 'PUB_ARGS="' + pub_args + '" SUB_ARGS="' + sub_args + '" PUBSUB_ARGS="' + pubsub_args + '" '
try:
out = subprocess.check_output(command_prerequisites + '@DOCKER_EXECUTABLE@ compose -f delivery_mechanisms.compose.yml up',
stderr=subprocess.STDOUT,
Expand Down Expand Up @@ -54,21 +64,17 @@ def test_delivery_mechanisms(pub_args, sub_args, repetitions):
assert(ret)

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
('--mechanism tcp', '--mechanism udp', '--mechanism shm -i'),
('--mechanism shm', '--mechanism data-sharing', '--mechanism intra-process -i')
]

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

command_prerequisites = 'PUB_ARGS="' + pub_args + '" SUB_ARGS="' + sub_args + '" '
command_prerequisites = 'PUB_ARGS="' + pub_args + '" SUB_ARGS="' + sub_args + '" PUBSUB_ARGS="' + pubsub_args + '" '
try:
out = subprocess.check_output(command_prerequisites + '@DOCKER_EXECUTABLE@ compose -f delivery_mechanisms.compose.yml up',
stderr=subprocess.STDOUT,
Expand All @@ -88,17 +94,17 @@ def test_delivery_mechanisms_timeout(pub_args, sub_args):
assert(ret)

expected_output_test_cases = [
('--mechanism tcp', '--unknown-argument', 'Unsupported', 1)
('--unknown-argument', '--unknown-argument', '--mechanism tcp', 'Unsupported', 1)
]

@pytest.mark.parametrize("pub_args, sub_args, expected_message, n_messages", expected_output_test_cases)
def test_delivery_mechanisms_expected_output(pub_args, sub_args, expected_message, n_messages):
@pytest.mark.parametrize("pub_args, sub_args, pubsub_args, expected_message, n_messages", expected_output_test_cases)
def test_delivery_mechanisms_expected_output(pub_args, sub_args, pubsub_args, expected_message, n_messages):
"""."""
ret = False
out = ''
render_out = ''

command_prerequisites = 'PUB_ARGS="' + pub_args + '" SUB_ARGS="' + sub_args + '" '
command_prerequisites = 'PUB_ARGS="' + pub_args + '" SUB_ARGS="' + sub_args + '" PUBSUB_ARGS="' + pubsub_args + '" '
try:
out = subprocess.check_output(command_prerequisites + '@DOCKER_EXECUTABLE@ compose -f delivery_mechanisms.compose.yml up',
stderr=subprocess.STDOUT,
Expand Down

0 comments on commit 4434cb0

Please sign in to comment.