Skip to content

Commit 2ce9dbe

Browse files
US47936 added connect timeout. Made request and connect timeout configurable via settings. (#1728)
1 parent 5902bf4 commit 2ce9dbe

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

bzt/bza.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -799,23 +799,23 @@ class HappysocksClient:
799799
"""
800800
HEADER_AUTH_TOKEN = "x-auth-token"
801801
HEADER_BZM_SESSION = "x-bzm-session"
802-
REQUEST_TIMEOUT = 10
803802

804803
def __init__(self, happysocks_address: str, session_id: str, session_token: str, verbose_logging=False,
805-
verify_ssl=True) -> None:
804+
verify_ssl=True, request_timeout=10, connect_timeout=7) -> None:
806805
super().__init__()
807806
self._log = logging.getLogger(self.__class__.__name__)
808807
parsed_url = urlparse(happysocks_address)
809808
self._session_token = session_token
810809
self._session_id = session_id
811810
self._happysocks_address = f"{parsed_url.scheme}://{parsed_url.netloc}"
812811
self._socketio_path = f"{parsed_url.path.rstrip('/')}/api-ws"
812+
self._connect_timeout = connect_timeout
813813
# socketio logging is too verbose by default
814814
socketio_logger = logging.getLogger("SocketIO") if verbose_logging else False
815815
http_session = requests.Session()
816816
http_session.verify = verify_ssl
817817
self._sio = socketio.Client(http_session=http_session, logger=socketio_logger, engineio_logger=socketio_logger,
818-
request_timeout=HappysocksClient.REQUEST_TIMEOUT)
818+
request_timeout=request_timeout)
819819
self._engine_namespace = HappysocksEngineNamespace()
820820
self._sio.register_namespace(self._engine_namespace)
821821

@@ -826,11 +826,17 @@ def connect(self):
826826
}
827827
full_address = f"{self._happysocks_address}{self._socketio_path}"
828828
self._log.info(f"Connecting to happysocks server {full_address}")
829+
start_time = time.time()
829830
try:
830831
self._sio.connect(self._happysocks_address, namespaces=[HappysocksEngineNamespace.NAMESPACE],
831-
transports=['websocket'], socketio_path=self._socketio_path, headers=headers)
832+
transports=['websocket'], socketio_path=self._socketio_path, headers=headers,
833+
wait_timeout=self._connect_timeout)
834+
end_time = time.time()
835+
self._log.info(f"Connected to happysocks server ({round(end_time - start_time, 2)}s)")
832836
except ConnectionError as e:
833-
raise TaurusNetworkError(f"Failed to connect to happysocks server {full_address}") from e
837+
end_time = time.time()
838+
raise TaurusNetworkError(
839+
f"Failed to connect to happysocks server {full_address} ({round(end_time - start_time, 2)}s)") from e
834840

835841
def connected(self):
836842
"""
@@ -846,6 +852,7 @@ def disconnect(self):
846852
if self._sio._reconnect_abort:
847853
self._sio._reconnect_abort.set()
848854
self._sio.disconnect()
855+
self._log.info("Disconnected from happysocks server")
849856

850857
def send_engine_metrics(self, metrics_batch: List[dict]):
851858
self._log.debug(f"Sending {len(metrics_batch)} metrics items to happysocks")

bzt/modules/blazemeter/blazemeter_reporter.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,11 @@ def prepare(self):
149149
happysocks_address = self.settings.get("happysocks-address")
150150
if happysocks_address and self._sess_id and signature:
151151
self.log.info(f"Engine metrics will be sent to '{happysocks_address}'")
152+
request_timeout = self.settings.get("happysocks-request-timeout", 10)
153+
connect_timeout = self.settings.get("happysocks-connect-timeout", 7)
152154
self.happysocks_client = HappysocksClient(happysocks_address, self._sess_id, signature,
153-
happysocks_verbose_logging, happysocks_verify_ssl)
155+
happysocks_verbose_logging, happysocks_verify_ssl,
156+
request_timeout, connect_timeout)
154157
else:
155158
reason = ""
156159
if not happysocks_address:

0 commit comments

Comments
 (0)