Skip to content

Commit

Permalink
Add router error check to test
Browse files Browse the repository at this point in the history
  • Loading branch information
sashacmc committed Dec 13, 2024
1 parent ef0ebb8 commit b387118
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/transport/unicast/lease.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ void *_zp_unicast_lease_task(void *ztu_arg) {
// Reset the lease parameters
ztu->_received = false;
} else {
// THIS LOG STRING USED IN TEST, change with caution
_Z_INFO("Closing session because it has expired after %zums", ztu->_common._lease);
_zp_unicast_failed(ztu);
return 0;
Expand Down
1 change: 1 addition & 0 deletions src/transport/unicast/transport.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ static z_result_t _z_unicast_handshake_client(_z_transport_unicast_establish_par
_z_t_msg_clear(&oam);
ret = _Z_ERR_MESSAGE_UNEXPECTED;
}
// THIS LOG STRING USED IN TEST, change with caution
_Z_DEBUG("Received Z_OPEN(Ack)");
param->_lease = oam._body._open._lease; // The session lease
// The initial SN at RX side. Initialize the session as we had already received
Expand Down
27 changes: 22 additions & 5 deletions tests/connection_restore.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
WAIT_MESSAGE_TIMEOUT_S = 15
DISCONNECT_MESSAGE = "Closing session because it has expired"
CONNECT_MESSAGE = "Z_OPEN(Ack)"
ROUTER_ERROR_MESSAGE = "ERROR"
ZENOH_PORT = "7447"

ROUTER_ARGS = ['-l', f'tcp/0.0.0.0:{ZENOH_PORT}', '--no-multicast-scouting']
Expand All @@ -22,8 +23,7 @@ def run_process(command, output_collector, process_list):
process_list.append(process)
for line in iter(process.stdout.readline, ''):
print("--", line.strip())
if output_collector is not None:
output_collector.append(line.strip())
output_collector.append(line.strip())
process.stdout.close()
process.wait()

Expand Down Expand Up @@ -62,13 +62,22 @@ def wait_message(client_output, message):
return False


def check_router_errors(router_output):
for line in router_output:
if ROUTER_ERROR_MESSAGE in line:
print("Router have an error: ", line)
return False
return True


def test_connection(router_command, client_command, timeout, wait_disconnect):
print(f"Drop test {client_command} for timeout {timeout}")
router_output = []
client_output = []
process_list = []
blocked = False
try:
run_background(router_command, None, process_list)
run_background(router_command, router_output, process_list)
time.sleep(ROUTER_INIT_TIMEOUT_S)

run_background(client_command, client_output, process_list)
Expand Down Expand Up @@ -105,6 +114,9 @@ def test_connection(router_command, client_command, timeout, wait_disconnect):
print("Failed to restore connection.")
return False

if not check_router_errors(router_output):
return False

print(f"Drop test {client_command} for timeout {timeout} passed")
return True
finally:
Expand All @@ -115,11 +127,12 @@ def test_connection(router_command, client_command, timeout, wait_disconnect):

def test_restart(router_command, client_command, timeout):
print(f"Restart test {client_command} for timeout {timeout}")
router_output = []
client_output = []
router_process_list = []
client_process_list = []
try:
run_background(router_command, None, router_process_list)
run_background(router_command, router_output, router_process_list)
time.sleep(ROUTER_INIT_TIMEOUT_S)

run_background(client_command, client_output, client_process_list)
Expand All @@ -136,14 +149,18 @@ def test_restart(router_command, client_command, timeout):
time.sleep(timeout)

print("Start router...")
run_background(router_command, None, router_process_list)
run_background(router_command, router_output, router_process_list)
time.sleep(ROUTER_INIT_TIMEOUT_S)

if wait_message(client_output, CONNECT_MESSAGE):
print("Connection restored successfully.")
else:
print("Failed to restore connection.")
return False

if not check_router_errors(router_output):
return False

print(f"Restart test {client_command} for timeout {timeout} passed")
return True
finally:
Expand Down

0 comments on commit b387118

Please sign in to comment.