Skip to content

Commit

Permalink
Refs #21095: split discovery server example
Browse files Browse the repository at this point in the history
Signed-off-by: Mario Dominguez <[email protected]>
  • Loading branch information
Mario-DL committed Jun 10, 2024
1 parent 9ff5b20 commit 8c07ead
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 52 deletions.
52 changes: 0 additions & 52 deletions test/examples/test_configuration.py
Original file line number Diff line number Diff line change
@@ -1,58 +1,6 @@
import subprocess
import pytest

"""
Expected output test cases for Discovery Server example.
Each element is a ternary (pub_args, sub_args, server_args)
"""
discovery_server_test_cases = [
('--samples 10', '--samples 10', '--timeout 5', '--id 2 --listening-port 11400 --timeout 1'),
('--connection-port 11500 --samples 10', '--connection-port 11500 --samples 10', '--listening-port 11500 --timeout 5', '--id 2 --listening-port 11400 --timeout 1'),
('--transport tcpv4 --samples 10', '--transport tcpv4 --samples 10', '--transport tcpv4 --timeout 5', '--id 2 --listening-port 11400 --timeout 1'),
('--connection-ds-id 1 --samples 10', '--connection-ds-id 1 --samples 10', '--id 1 --timeout 5', '--id 2 --listening-port 11400 --timeout 1'),
('--connection-ds-id 1 --samples 10', '--connection-ds-id 2 --connection-port 11400 --samples 10', '--id 1 --timeout 5 --connection-ds-id 2 --connection-port 11400', '--id 2 --listening-port 11400 --timeout 5')
]

@pytest.mark.parametrize("pub_args, sub_args, server1_args, server2_args", discovery_server_test_cases)
def test_discovery_server(pub_args, sub_args, server1_args, server2_args):
"""."""
ret = False
out = ''
command_args = 'PUB_ARGS="' + pub_args + '" SUB_ARGS="' + sub_args + '" SERVER1_ARGS="' + server1_args + '" SERVER2_ARGS="' + server2_args + '" '
try:
out = subprocess.check_output(
command_args + '@DOCKER_EXECUTABLE@ compose -f discovery_server.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
54 changes: 54 additions & 0 deletions test/examples/test_discovery_server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import subprocess
import pytest

"""
Expected output test cases for Discovery Server example.
Each element is a ternary (pub_args, sub_args, server_args)
"""
discovery_server_test_cases = [
('--samples 10', '--samples 10', '--timeout 5', '--id 2 --listening-port 11400 --timeout 1'),
('--connection-port 11500 --samples 10', '--connection-port 11500 --samples 10', '--listening-port 11500 --timeout 5', '--id 2 --listening-port 11400 --timeout 1'),
('--transport tcpv4 --samples 10', '--transport tcpv4 --samples 10', '--transport tcpv4 --timeout 5', '--id 2 --listening-port 11400 --timeout 1'),
('--connection-ds-id 1 --samples 10', '--connection-ds-id 1 --samples 10', '--id 1 --timeout 5', '--id 2 --listening-port 11400 --timeout 1'),
('--connection-ds-id 1 --samples 10', '--connection-ds-id 2 --connection-port 11400 --samples 10', '--id 1 --timeout 5 --connection-ds-id 2 --connection-port 11400', '--id 2 --listening-port 11400 --timeout 5')
]

@pytest.mark.parametrize("pub_args, sub_args, server1_args, server2_args", discovery_server_test_cases)
def test_discovery_server(pub_args, sub_args, server1_args, server2_args):
"""."""
ret = False
out = ''
command_args = 'PUB_ARGS="' + pub_args + '" SUB_ARGS="' + sub_args + '" SERVER1_ARGS="' + server1_args + '" SERVER2_ARGS="' + server2_args + '" '
try:
out = subprocess.check_output(
command_args + '@DOCKER_EXECUTABLE@ compose -f discovery_server.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)

0 comments on commit 8c07ead

Please sign in to comment.