chore: node readiness (#35)

* test: wait longer for info endpoint to start

* test: health endpoint response parsing

* fix: health endpoint response parsing

* fix: remove debug from health response parsing

* fix: mark on chain tests to skip again

* fix: check_healthy accepts both text and json response

* fix: delete test workflow

* fix: simplify if statements
This commit is contained in:
Roman Zajic 2024-05-08 20:50:05 +08:00 committed by GitHub
parent 151233fddb
commit 06281de7c8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 26 additions and 9 deletions

View File

@ -25,8 +25,8 @@ class REST(BaseClient):
return info_response.json() return info_response.json()
def health(self): def health(self):
health_response = self.rest_call_text("get", "health") health_response = self.rest_call("get", "health")
return health_response.text() return health_response.content
def get_peers(self): def get_peers(self):
get_peers_response = self.rest_call("get", "admin/v1/peers") get_peers_response = self.rest_call("get", "admin/v1/peers")

View File

@ -47,8 +47,8 @@ class WakuNode:
self._container = None self._container = None
logger.debug(f"WakuNode instance initialized with log path {self._log_path}") logger.debug(f"WakuNode instance initialized with log path {self._log_path}")
@retry(stop=stop_after_delay(5), wait=wait_fixed(0.1), reraise=True) @retry(stop=stop_after_delay(60), wait=wait_fixed(0.1), reraise=True)
def start(self, wait_for_node_sec=10, **kwargs): def start(self, wait_for_node_sec=20, **kwargs):
logger.debug("Starting Node...") logger.debug("Starting Node...")
self._docker_manager.create_network() self._docker_manager.create_network()
self._ext_ip = self._docker_manager.generate_random_ext_ip() self._ext_ip = self._docker_manager.generate_random_ext_ip()
@ -188,17 +188,34 @@ class WakuNode:
def ensure_ready(self, timeout_duration=10): def ensure_ready(self, timeout_duration=10):
@retry(stop=stop_after_delay(timeout_duration), wait=wait_fixed(0.1), reraise=True) @retry(stop=stop_after_delay(timeout_duration), wait=wait_fixed(0.1), reraise=True)
def check_healthy(node=self):
self.health_response = node.health()
if self.health_response == b"Node is healthy":
logger.info("Node is healthy !!")
return
try:
self.health_response = json.loads(self.health_response)
except Exception as ex:
raise AttributeError(f"Unknown health response format {ex}")
if self.health_response.get("nodeHealth") != "Ready":
raise AssertionError("Waiting for the node health status: Ready")
for p in self.health_response.get("protocolsHealth"):
if p.get("Rln Relay") != "Ready":
raise AssertionError("Waiting for the Rln relay status: Ready")
logger.info("Node protocols are initialized !!")
@retry(stop=stop_after_delay(5), wait=wait_fixed(0.1), reraise=True)
def check_ready(node=self): def check_ready(node=self):
node.info_response = node.info() node.info_response = node.info()
logger.info("REST service is ready !!") logger.info("REST service is ready !!")
check_healthy()
check_ready() check_ready()
@retry(stop=stop_after_delay(10), wait=wait_fixed(1), reraise=True)
def ensure_healthy(self):
self.health_response = self.health()
logger.info("Node is healthy !!")
def get_enr_uri(self): def get_enr_uri(self):
try: try:
return self.info_response["enrUri"] return self.info_response["enrUri"]