Skip to content

Commit

Permalink
Catch ZMQ connection errors (#157)
Browse files Browse the repository at this point in the history
These should only occur if the Django server is up and not the ZMQ server, but they do occur, so it's nice to catch them and reraise as ConnectionErrors.
  • Loading branch information
sindrehan authored Nov 27, 2023
1 parent c8d152b commit 7977137
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
7 changes: 5 additions & 2 deletions blueye/sdk/drone.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,11 @@ def connect(
self._ctrl_client.start()
self._watchdog_publisher.start()

self.ping()
connect_resp = self._req_rep_client.connect_client(client_info=client_info)
try:
self.ping()
connect_resp = self._req_rep_client.connect_client(client_info=client_info)
except blueye.protocol.exceptions.ResponseTimeout as e:
raise ConnectionError("Could not establish connection with drone") from e
logger.info(f"Connection successful, client id: {connect_resp.client_id}")
logger.info(f"Client id in control: {connect_resp.client_id_in_control}")
logger.info(f"There are {len(connect_resp.connected_clients)-1} other clients connected")
Expand Down
6 changes: 6 additions & 0 deletions tests/test_sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ def test_angle_conversion(self, mocked_drone, old_angle, new_angle):
assert pose["yaw"] == new_angle


def test_zmq_connection_error(mocked_drone):
mocked_drone._req_rep_client.ping.side_effect = bp.exceptions.ResponseTimeout
with pytest.raises(ConnectionError):
mocked_drone.connect()


def test_feature_list(mocked_drone):
mocked_drone._update_drone_info()
assert mocked_drone.features == ["lasers", "harpoon"]
Expand Down

0 comments on commit 7977137

Please sign in to comment.