Skip to content

Commit 44499af

Browse files
committed
Address review comments
1 parent 11838c5 commit 44499af

File tree

1 file changed

+30
-8
lines changed

1 file changed

+30
-8
lines changed

src/python_testing/TC_WEBRTCRTestBase.py

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#
1717

1818
import logging
19+
1920
import websockets
2021

2122
from matter.testing.matter_testing import MatterBaseTest
@@ -45,14 +46,35 @@ async def send_command(self, command):
4546
2. Sends the command
4647
3. Waits for and receives the response
4748
4. Logs the connection, command, and response status
49+
50+
Raises:
51+
Exception: Re-raises any exceptions after logging them clearly
4852
"""
49-
async with websockets.connect(SERVER_URI) as websocket:
50-
logging.info(f"Connected to {SERVER_URI}")
53+
try:
54+
async with websockets.connect(SERVER_URI) as websocket:
55+
logging.info(f"Connected to {SERVER_URI}")
56+
57+
# Send command
58+
logging.info(f"Sending command: {command}")
59+
await websocket.send(command)
60+
61+
# Receive response
62+
await websocket.recv()
63+
logging.info("Received command response")
64+
65+
except ConnectionRefusedError as e:
66+
logging.error(f"Failed to connect to WebSocket server at {SERVER_URI}: Connection refused. "
67+
f"Is the DUT WebSocket server running? Error: {e}")
68+
raise
69+
70+
except websockets.exceptions.WebSocketException as e:
71+
logging.error(f"WebSocket error while communicating with {SERVER_URI}: {e}")
72+
raise
5173

52-
# Send command
53-
logging.info(f"Sending command: {command}")
54-
await websocket.send(command)
74+
except OSError as e:
75+
logging.error(f"Network error while connecting to {SERVER_URI}: {e}")
76+
raise
5577

56-
# Receive response
57-
await websocket.recv()
58-
logging.info("Received command response")
78+
except Exception as e:
79+
logging.error(f"Unexpected error while sending command '{command}' to {SERVER_URI}: {e}")
80+
raise

0 commit comments

Comments
 (0)