Skip to content

Commit

Permalink
Refs #21188: Update tests
Browse files Browse the repository at this point in the history
Signed-off-by: eduponz <eduardoponz@eprosima.com>
  • Loading branch information
EduPonz committed Jul 10, 2024
1 parent db19259 commit 05ba0c0
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 20 deletions.
4 changes: 2 additions & 2 deletions test/examples/request_reply.compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ services:
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/request_reply@FILE_EXTENSION@
FASTDDS_DEFAULT_PROFILES_FILE: @PROJECT_BINARY_DIR@/examples/cpp/request_reply/request_reply_profile.xml
command: @SHELL_EXECUTABLE@ -c "$${EXAMPLE_DIR}/request_reply@FILE_EXTENSION@ client 1 + 1 & timeout --preserve-status 3 $${EXAMPLE_DIR}/request_reply@FILE_EXTENSION@ server"
command: @SHELL_EXECUTABLE@ -c "$${EXAMPLE_DIR}/request_reply@FILE_EXTENSION@ client 2 5 & timeout --preserve-status 3 $${EXAMPLE_DIR}/request_reply@FILE_EXTENSION@ server"

client:
image: @DOCKER_IMAGE_NAME@
Expand All @@ -38,4 +38,4 @@ services:
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/request_reply@FILE_EXTENSION@
FASTDDS_DEFAULT_PROFILES_FILE: @PROJECT_BINARY_DIR@/examples/cpp/request_reply/request_reply_profile.xml
command: @SHELL_EXECUTABLE@ -c "$${EXAMPLE_DIR}/request_reply@FILE_EXTENSION@ client 2 x 3"
command: @SHELL_EXECUTABLE@ -c "$${EXAMPLE_DIR}/request_reply@FILE_EXTENSION@ client 67 24"
8 changes: 4 additions & 4 deletions test/examples/request_reply_isolated.compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ services:
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/request_reply@FILE_EXTENSION@
FASTDDS_DEFAULT_PROFILES_FILE: @PROJECT_BINARY_DIR@/examples/cpp/request_reply/request_reply_profile.xml
command: @SHELL_EXECUTABLE@ -c "$${EXAMPLE_DIR}/request_reply@FILE_EXTENSION@ client 2 + 3"
command: @SHELL_EXECUTABLE@ -c "$${EXAMPLE_DIR}/request_reply@FILE_EXTENSION@ client 2 5"
depends_on:
- server-1
- server-2
Expand All @@ -67,7 +67,7 @@ services:
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/request_reply@FILE_EXTENSION@
FASTDDS_DEFAULT_PROFILES_FILE: @PROJECT_BINARY_DIR@/examples/cpp/request_reply/request_reply_profile.xml
command: @SHELL_EXECUTABLE@ -c "$${EXAMPLE_DIR}/request_reply@FILE_EXTENSION@ client 3 - 2"
command: @SHELL_EXECUTABLE@ -c "$${EXAMPLE_DIR}/request_reply@FILE_EXTENSION@ client 67 24"
depends_on:
- server-1
- server-2
Expand All @@ -83,7 +83,7 @@ services:
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/request_reply@FILE_EXTENSION@
FASTDDS_DEFAULT_PROFILES_FILE: @PROJECT_BINARY_DIR@/examples/cpp/request_reply/request_reply_profile.xml
command: @SHELL_EXECUTABLE@ -c "$${EXAMPLE_DIR}/request_reply@FILE_EXTENSION@ client 3 x 2"
command: @SHELL_EXECUTABLE@ -c "$${EXAMPLE_DIR}/request_reply@FILE_EXTENSION@ client 3 2"
depends_on:
- server-1
- server-2
Expand All @@ -99,7 +99,7 @@ services:
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/request_reply@FILE_EXTENSION@
FASTDDS_DEFAULT_PROFILES_FILE: @PROJECT_BINARY_DIR@/examples/cpp/request_reply/request_reply_profile.xml
command: @SHELL_EXECUTABLE@ -c "$${EXAMPLE_DIR}/request_reply@FILE_EXTENSION@ client 20 / 5"
command: @SHELL_EXECUTABLE@ -c "$${EXAMPLE_DIR}/request_reply@FILE_EXTENSION@ client 20 5"
depends_on:
- server-1
- server-2
38 changes: 33 additions & 5 deletions test/examples/test_request_reply.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,46 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import re
import subprocess

def parse_response(client_responses: dict, response: str):
"""."""
# Define the regex pattern with two capturing groups
pattern = r"ID '(\d+)' with result: '(-?\d+)'"

# Use re.search to find the first match
match = re.search(pattern, response)

if match:
id_str = match.group(1) # First capturing group
result_int = int(match.group(2)) # Second capturing group, convert to int

client_responses[id_str] = result_int

return client_responses


def test_request_reply():
"""."""
expected_responses = {
'request_reply-server-client-1': 2,
'request_reply-client-1': 6
'request_reply-server-client-1': {
'1': 7,
'2': -3,
'3': 10,
'4': 0
},
'request_reply-client-1': {
'1': 91,
'2': 43,
'3': 1608,
'4': 2
},
}

responses = {
'request_reply-server-client-1': None,
'request_reply-client-1': None,
'request_reply-server-client-1': {},
'request_reply-client-1': {},
}

ret = True
Expand All @@ -40,7 +68,7 @@ def test_request_reply():
for line in out:
for client in expected_responses:
if client in line and 'Reply received from server' in line:
responses[client] = int(line.rstrip().split(' ')[-1])
responses[client] = parse_response(responses[client], line)

for client in responses:
if responses[client] != expected_responses[client]:
Expand Down
56 changes: 47 additions & 9 deletions test/examples/test_request_reply_isolated.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,60 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import re
import subprocess

def parse_response(client_responses: dict, response: str):
"""."""
# Define the regex pattern with two capturing groups
pattern = r"ID '(\d+)' with result: '(-?\d+)'"

# Use re.search to find the first match
match = re.search(pattern, response)

if match:
id_str = match.group(1) # First capturing group
result_int = int(match.group(2)) # Second capturing group, convert to int

client_responses[id_str] = result_int

return client_responses


def test_request_reply_isolated():
"""."""
expected_responses = {
'request_reply_isolated-client-1-1': 5,
'request_reply_isolated-client-2-1': 1,
'request_reply_isolated-client-3-1': 6,
'request_reply_isolated-client-4-1': 4
'request_reply_isolated-client-1-1': {
'1': 7,
'2': -3,
'3': 10,
'4': 0
},
'request_reply_isolated-client-2-1': {
'1': 91,
'2': 43,
'3': 1608,
'4': 2
},
'request_reply_isolated-client-3-1': {
'1': 5,
'2': 1,
'3': 6,
'4': 1
},
'request_reply_isolated-client-4-1': {
'1': 25,
'2': 15,
'3': 100,
'4': 4
}
}

responses = {
'request_reply_isolated-client-1-1': None,
'request_reply_isolated-client-2-1': None,
'request_reply_isolated-client-3-1': None,
'request_reply_isolated-client-4-1': None
'request_reply_isolated-client-1-1': {},
'request_reply_isolated-client-2-1': {},
'request_reply_isolated-client-3-1': {},
'request_reply_isolated-client-4-1': {}
}

ret = True
Expand All @@ -44,7 +82,7 @@ def test_request_reply_isolated():
for line in out:
for client in expected_responses:
if client in line and 'Reply received from server' in line:
responses[client] = int(line.rstrip().split(' ')[-1])
responses[client] = parse_response(responses[client], line)

for client in responses:
if responses[client] != expected_responses[client]:
Expand Down

0 comments on commit 05ba0c0

Please sign in to comment.