mirror of
https://github.com/optim-enterprises-bv/openlan-cgw.git
synced 2025-10-29 17:32:21 +00:00
Tests: core: add timeout values for common clients
Force redis, PSQL, kafka clients to have a strict timeout value for any requests. It's done to ensure our tests do not hang for an unknown period of time in case if something goes wrong. Signed-off-by: Oleksandr Mazur <oleksandr.mazur@plvision.eu>
This commit is contained in:
@@ -6,12 +6,14 @@ def cgw_metric_get(host: str = "localhost", port: int = 8080) -> str:
|
||||
metrics = ""
|
||||
|
||||
try:
|
||||
r = requests.get(f"http://{host}:{port}/metrics")
|
||||
print("CGW metrics: " + str(r.status_code) + ', txt:' + r.text)
|
||||
# Try to fetch metrics with 5 seconds timeout value
|
||||
r = requests.get(f"http://{host}:{port}/metrics", timeout=5)
|
||||
print("CGW metrics ret code: " + str(r.status_code))
|
||||
assert r is not None and r.status_code == 200, \
|
||||
f"CGW metrics is not available"
|
||||
metrics = r.text
|
||||
except:
|
||||
except Exception as e:
|
||||
print("CGW metrics: raised exception when tried to fetch metrics:" + e)
|
||||
raise Exception('CGW metrics fetch failed (Not running?)')
|
||||
|
||||
return metrics
|
||||
|
||||
@@ -126,7 +126,9 @@ class Device:
|
||||
|
||||
def connect(self):
|
||||
if self._socket is None:
|
||||
self._socket = client.connect(self.server_addr, ssl=self.ssl_context, open_timeout=7200)
|
||||
# 20 seconds is more then enough to establish conne and exchange
|
||||
# them handshakes.
|
||||
self._socket = client.connect(self.server_addr, ssl=self.ssl_context, open_timeout=20, close_timeout=20)
|
||||
return self._socket
|
||||
|
||||
def disconnect(self):
|
||||
|
||||
@@ -132,7 +132,11 @@ class Producer:
|
||||
|
||||
def connect(self) -> kafka.KafkaProducer:
|
||||
if self.is_connected() is False:
|
||||
self.conn = kafka.KafkaProducer(bootstrap_servers=self.db, client_id="producer")
|
||||
self.conn = kafka.KafkaProducer(
|
||||
bootstrap_servers=self.db,
|
||||
client_id="producer",
|
||||
max_block_ms=12000,
|
||||
request_timeout_ms=12000)
|
||||
logger.info("producer: connected to kafka")
|
||||
else:
|
||||
logger.info("producer: already connected to kafka")
|
||||
|
||||
@@ -12,7 +12,10 @@ class RedisClient:
|
||||
"""Connect to the Redis database."""
|
||||
try:
|
||||
# Establish connection to Redis server
|
||||
self.connection = redis.StrictRedis(host=self.host, port=self.port, db=0, decode_responses=True)
|
||||
self.connection = redis.StrictRedis(
|
||||
host=self.host, port=self.port,
|
||||
db=0, decode_responses=True, socket_timeout=5.0,
|
||||
socket_connect_timeout=2.0)
|
||||
# Check if the connection is successful
|
||||
self.connection.ping()
|
||||
print(f"Connected to Redis server at {self.host}:{self.port}")
|
||||
|
||||
Reference in New Issue
Block a user