Skip to content

Commit

Permalink
Refs #20575: Add more tests
Browse files Browse the repository at this point in the history
Signed-off-by: JesusPoderoso <jesuspoderoso@eprosima.com>
  • Loading branch information
JesusPoderoso committed Apr 8, 2024
1 parent 0956184 commit eb6ba0c
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 49 deletions.
2 changes: 1 addition & 1 deletion examples/cpp/configuration/CLIParser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class CLIParser
uint32_t lifespan = fastrtps::Duration_t::INFINITE_SECONDS;
LivelinessQosPolicyKind liveliness = LivelinessQosPolicyKind::AUTOMATIC_LIVELINESS_QOS;
uint32_t liveliness_lease = fastrtps::Duration_t::INFINITE_SECONDS;
uint32_t liveliness_assert = fastrtps::Duration_t::INFINITE_SECONDS;
uint32_t liveliness_assert = fastrtps::Duration_t::INFINITE_SECONDS-1;
OwnershipQosPolicyKind ownership = OwnershipQosPolicyKind::SHARED_OWNERSHIP_QOS;
std::string partitions = "";
};
Expand Down
6 changes: 3 additions & 3 deletions examples/cpp/configuration/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,11 @@ The following table represents the compatibility matrix (compatible ✔️ vs in
<th rowspan="2" style="text-align:center">Data reader</th>
<td>Positive ACKs <i>enabled</i></td>
<td>✔️</td>
<td></td>
<td></td>
</tr>
<tr style="text-align:center">
<td>Positive ACKs <i>disabled</i></td>
<td></td>
<td></td>
<td>✔️</td>
</tr>
</table>
Expand Down Expand Up @@ -233,7 +233,7 @@ Publishing any new data value implicitly asserts the data writer's liveliness, b

* **``MANUAL_BY_PARTICIPANT``**: If one of the entities in the publishing side asserts its liveliness, the service deduces that all other entities within the same DomainParticipant are also alive.

* **``MANUAL_BY_TOPIC_LIVELINESS_QOS``**: requires at least one instance within the data writer is asserted to consider it alive.
* **``MANUAL_BY_TOPIC``**: requires at least one instance within the data writer is asserted to consider it alive.

Finally, the argument **``--liveliness-assert``** ``<period>`` configures the period between consecutive liveliness messages sent by the data writer.
It is only taken into account when the liveliness QoS kind is **``AUTOMATIC``** or **``MANUAL_BY_PARTICIPANT``**, and this period is **lower** than the liveliness lease duration.
Expand Down
116 changes: 71 additions & 45 deletions test/examples/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,56 @@
import pytest

config_test_cases = [
('', ''), # Default configuration
('--profile-participant configuration_participant_profile', '--profile-participant configuration_participant_profile'),
('--profile-writer configuration_datawriter_profile', '--profile-reader configuration_datareader_profile' ),
('--transport DEFAULT', '--transport DEFAULT'),
('--transport DEFAULT', '--transport UDPv4'),
('--transport UDPv4', '--transport UDPv4'),
('--transport LARGE_DATA', '--transport LARGE_DATA'),
# TODO test lifespan QoS
# TODO test liveliness QoS
# TODO test ownership QoS
# TODO test disable positive acks QoS
# TODO test partitions QoS
('--partition configuration_example_partition', '--partition configuration_example_partition'),
('--partition \'configuration_example_partition\'', '--partition \'configuration_example_partition\''),
('--partition "configuration_example_partition"', '--partition "configuration_example_partition"'),
('--keep-last 10 --transport DEFAULT', '--keep-last 10 --transport DEFAULT'), # Builtin transports
('--keep-last 10 --transport DEFAULT', '--keep-last 10 --transport UDPv4'),
('--keep-last 10 --transport UDPv4', '--keep-last 10 --transport UDPv4'),
('--keep-last 10 --transport LARGE_DATA', '--keep-last 10 --transport LARGE_DATA'),
('--keep-last 10 --deadline 300', '--keep-last 10 --deadline 300'), # Deadline QoS
('--keep-last 10 --deadline 80', '--keep-last 10 --deadline 80'),
('--keep-last 10 --disable-positive-ack', '--keep-last 10 --disable-positive-ack'), # Disable positive ACKs QoS
('--keep-last 10 --disable-positive-ack --ack-keep-duration 10', '--keep-last 10 --disable-positive-ack'),
('--keep-last 100', '--keep-last 100'), # History QoS
('--keep-last 10', '--keep-all'),
('--keep-all', '--keep-all'),
('--keep-last 10 --lifespan 500', '--keep-last 10 --lifespan 500'), # Lifespan QoS
('--keep-last 10 --liveliness 500 --liveliness-assert 400', '--keep-last 10 --liveliness 500 --liveliness-assert 400'), # Liveliness QoS
('--keep-last 10 --liveliness-kind AUTOMATIC', '--keep-last 10 --liveliness-kind AUTOMATIC'),
('--keep-last 10 --liveliness-kind MANUAL_BY_PARTICIPANT', '--keep-last 10 --liveliness-kind MANUAL_BY_PARTICIPANT'),
('--keep-last 10 --liveliness-kind MANUAL_BY_TOPIC', '--keep-last 10 --liveliness-kind MANUAL_BY_TOPIC'),
('--keep-last 10 --liveliness-assert 500', '--keep-last 10 --liveliness-assert 500'),
('--keep-last 10 --ownership', '--keep-last 10 --ownership'), # Ownership QoS
('--keep-last 10 --ownership --strength 10', '--keep-last 10 --ownership'),
('--keep-last 10 --partition configuration_example_partition', '--keep-last 10 --partition configuration_example_partition'), # Partition QoS
('--keep-last 10 --partition \'configuration_example_partition\'', '--keep-last 10 --partition \'configuration_example_partition\''),
('--keep-last 10 --partition "configuration_example_partition"', '--keep-last 10 --partition "configuration_example_partition"'),
('--keep-last 10 --profile-participant configuration_participant_profile', '--keep-last 10 --profile-participant configuration_participant_profile'),
('--keep-last 10 --profile-writer configuration_datawriter_profile', '--keep-last 10 --profile-reader configuration_datareader_profile' ),
('--keep-last 10 --async', '--keep-last 10 '), # Publish mode QoS
('--keep-last 10 --max-instances 1', '--keep-last 10 --max-instances 1'), # Resource limits QoS
('--keep-last 10 --max-samples-per-instance 10', '--keep-last 10 --max-samples-per-instance 10'),
('--keep-last 10 --max-instances 1 --max-samples-per-instance 10 --max-samples 10', '--keep-last 10 --max-instances 1 --max-samples-per-instance 10 --max-samples 10'),
]

@pytest.mark.parametrize("pub_args, sub_args", config_test_cases)
def test_configuration(pub_args, sub_args):
"""."""
ret = False
out = ''
pub_requirements = '--reliable --transient-local --keep-last 10'
sub_requirements = '--reliable --transient-local --keep-last 10'
pub_requirements = '-d 113 --reliable --transient-local'
sub_requirements = '-d 113 --reliable --transient-local'

command_prerequisites = 'PUB_ARGS="' + pub_requirements + ' ' + pub_args + '" SUB_ARGS="' + sub_requirements + ' ' + sub_args + '" '
try:
out = subprocess.check_output(command_prerequisites + '@DOCKER_EXECUTABLE@ compose -f configuration.compose.yml up',
stderr=subprocess.STDOUT,
shell=True,
timeout=30
).decode().split('\n')
timeout=40
)
render_out = out.decode().split('\n')

sent = 0
received = 0
for line in out:
for line in render_out:
if 'SENT' in line:
sent += 1
continue
Expand All @@ -51,52 +65,65 @@ def test_configuration(pub_args, sub_args):
ret = True
else:
print ('ERROR: sent: ' + str(sent) + ', but received: ' + str(received) + ' (expected: ' + str(sent * 2) + ')')
raise subprocess.CalledProcessError(1, '')
raise subprocess.CalledProcessError(1, out.decode())

except subprocess.CalledProcessError:
for l in out:
print(l)
except subprocess.CalledProcessError as e:
print (e.output)
#for l in e.output.split('\n'):
# print(l)
except subprocess.TimeoutExpired:
print('TIMEOUT')
print(out)

assert(ret)

timeout_test_cases = [
('--deadline 300', '--deadline 100'),
('--partition configuration_example_partition', '--partition other_partition'),
('--transport SHM', '--transport UDPv4'), # Builtin transports
('--deadline 300', '--deadline 100'), # Deadline QoS
('', '--disable-positive-ack'), # Disable positive ACKs QoS
('', '--transient-local'), # Durability QoS
#('--keep-last 10 --max-samples-per-instance 1', ''), # this one only displays warning from now on
('--liveliness-kind AUTOMATIC', '--liveliness-kind MANUAL_BY_PARTICIPANT'), # Liveliness QoS
('--liveliness-kind AUTOMATIC', '--liveliness-kind MANUAL_BY_TOPIC'),
('--liveliness-kind MANUAL_BY_PARTICIPANT', '--liveliness-kind MANUAL_BY_TOPIC'),
('--ownership', ''), # Ownership QoS
('', '--ownership'),
('--partition configuration_example_partition', '--partition other_partition'), # Partition QoS
('', '--reliable'), # Reliability QoS
]

@pytest.mark.parametrize("pub_args, sub_args", timeout_test_cases)
def test_configuration_timeout(pub_args, sub_args):
"""."""
ret = False
out = ''
pub_requirements = '--reliable --transient-local --keep-last 10'
sub_requirements = '--reliable --transient-local --keep-last 10'

command_prerequisites = 'PUB_ARGS="' + pub_requirements + ' ' + pub_args + '" SUB_ARGS="' + sub_requirements + ' ' + sub_args + '" '
command_prerequisites = 'PUB_ARGS="' + pub_args + '" SUB_ARGS="' + sub_args + '" '
try:
out = subprocess.check_output(command_prerequisites + '@DOCKER_EXECUTABLE@ compose -f configuration.compose.yml up',
stderr=subprocess.STDOUT,
shell=True,
timeout=10
).decode().split('\n')

except subprocess.CalledProcessError:
for l in out:
print(l)
)
except subprocess.CalledProcessError as e:
print (e.output)
except subprocess.TimeoutExpired:
ret = True
subprocess.check_output('@DOCKER_EXECUTABLE@ compose -f configuration.compose.yml down',
stderr=subprocess.STDOUT,
shell=True,
timeout=15
)

assert(ret)

expected_output_test_cases = [
('--deadline 80', '--deadline 80', 'Deadline missed!'),
('--deadline 80', '--deadline 80', 'Deadline missed!', '10'), # 10 = n samples sent
('--deadline 80', '--deadline 80', 'Requested deadline missed!', '20'), # 20 = n samples received (10 x 2)
]

@pytest.mark.parametrize("pub_args, sub_args, expected_message", expected_output_test_cases)
def test_configuration_expected_output(pub_args, sub_args, expected_message):
@pytest.mark.parametrize("pub_args, sub_args, expected_message, n_messages", expected_output_test_cases)
def test_configuration_expected_output(pub_args, sub_args, expected_message, n_messages):
"""."""
ret = False
out = ''
Expand All @@ -109,24 +136,23 @@ def test_configuration_expected_output(pub_args, sub_args, expected_message):
stderr=subprocess.STDOUT,
shell=True,
timeout=30
).decode().split('\n')
)
render_out = out.decode().split('\n')

count = 0
for line in out:
for line in render_out:
if expected_message in line:
count += 1
continue

# check if count equal SENT samples (forced to be 10 in the compose file)
if count == 10:
if count >= int(n_messages):
ret = True
else:
print ('ERROR: expected: 10 "' + expected_message + '" messages, but received ' + str(count))
raise subprocess.CalledProcessError(1, '')
raise subprocess.CalledProcessError(1, out.decode())

except subprocess.CalledProcessError:
for l in out:
print(l)
except subprocess.CalledProcessError as e:
print (e.output)
except subprocess.TimeoutExpired:
print('TIMEOUT')
print(out)
Expand Down

0 comments on commit eb6ba0c

Please sign in to comment.