Skip to content

Commit

Permalink
Refs #21094: Add test
Browse files Browse the repository at this point in the history
Signed-off-by: elianalf <62831776+elianalf@users.noreply.github.com>
  • Loading branch information
elianalf committed Jun 3, 2024
1 parent f946f6e commit 0fcf0e8
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 39 deletions.
29 changes: 29 additions & 0 deletions test/examples/custom_payload_pool.compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# 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/custom_payload_pool
command: @SHELL_EXECUTABLE@ -c "$${EXAMPLE_DIR}/custom_payload_pool@FILE_EXTENSION@ subscriber --samples 10"

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/custom_payload_pool
command: @SHELL_EXECUTABLE@ -c "$${EXAMPLE_DIR}/custom_payload_pool@FILE_EXTENSION@ publisher --samples 10"
depends_on:
- subscriber
116 changes: 77 additions & 39 deletions test/examples/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,83 @@
import subprocess
import pytest

def test_hello_world():
"""."""
ret = False
out = ''
try:
out = subprocess.check_output(
'@DOCKER_EXECUTABLE@ compose -f hello_world.compose.yml up',
stderr=subprocess.STDOUT,
shell=True,
timeout=30
).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 * 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)

def test_custom_payload_pool():
"""."""
ret = False
out = ''
try:
out = subprocess.check_output(
'@DOCKER_EXECUTABLE@ compose -f custom_payload_pool.compose.yml up',
stderr=subprocess.STDOUT,
shell=True,
timeout=30
).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 == received:
ret = True
else:
print('ERROR: sent: ' + str(sent) + ', but received: ' + str(received))
raise subprocess.CalledProcessError(1, '')

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

assert(ret)

config_test_cases = [
('--keep-last 10 --transport DEFAULT', '--keep-last 10 --transport DEFAULT'), # Builtin transports
('--keep-last 10 --transport DEFAULT', '--keep-last 10 --transport UDPv4'),
Expand Down Expand Up @@ -158,42 +235,3 @@ def test_configuration_expected_output(pub_args, sub_args, expected_message, n_m
print(out)

assert(ret)

def test_hello_world():
"""."""
ret = False
out = ''
try:
out = subprocess.check_output(
'@DOCKER_EXECUTABLE@ compose -f hello_world.compose.yml up',
stderr=subprocess.STDOUT,
shell=True,
timeout=30
).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 * 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 0fcf0e8

Please sign in to comment.