diff --git a/src/node/waku_node.py b/src/node/waku_node.py index 1a96d0617..ecd39c418 100644 --- a/src/node/waku_node.py +++ b/src/node/waku_node.py @@ -5,6 +5,7 @@ import random import re import shutil import string +import time import pytest import requests from src.libs.common import delay @@ -295,6 +296,30 @@ class WakuNode: check_healthy() check_ready() + def wait_for_connected(self, timeout=30): + deadline = time.time() + timeout + + while time.time() < deadline: + try: + raw = self.health() + health = json.loads(raw) if isinstance(raw, (str, bytes)) else raw + status = health.get("connectionStatus", "") + + if status == "Connected": + logger.debug("Node reached connectionStatus=Connected") + return + + except Exception as exc: + logger.debug("Health poll failed ") + + time.sleep(1) + + raise TimeoutError(f"Node did not reach connectionStatus='Connected' within {timeout}s.") + + def get_node_health(self): + raw = self.health() + return json.loads(raw) if isinstance(raw, (str, bytes)) else raw + def get_id(self): try: return self.info_response["listenAddresses"][0].split("/")[-1] @@ -517,7 +542,6 @@ class WakuNode: return self._container def generate_random_nodekey(self): - # Define the set of hexadecimal characters hex_chars = string.hexdigits.lower() # Generate a random 64-character string from the hex characters random_key = "".join(random.choice(hex_chars) for _ in range(64)) diff --git a/src/steps/common.py b/src/steps/common.py index ccdfcf533..593c81b3a 100644 --- a/src/steps/common.py +++ b/src/steps/common.py @@ -22,12 +22,17 @@ class StepsCommon: if not hasattr(self, "test_content_topic"): self.test_content_topic = "/test/1/default/proto" + @allure.step + def wait_for_node_connected(self, node, timeout=30): + node.wait_for_connected(timeout=timeout) + @allure.step @retry(stop=stop_after_delay(20), wait=wait_fixed(0.5), reraise=True) def add_node_peer(self, node, multiaddr_list, shards=[0, 1, 2, 3, 4, 5, 6, 7, 8]): if node.is_nwaku(): for multiaddr in multiaddr_list: node.add_peers([multiaddr]) + self.wait_for_node_connected(node) @allure.step @retry(stop=stop_after_delay(70), wait=wait_fixed(1), reraise=True) diff --git a/tests/filter/test_subscribe_create.py b/tests/filter/test_subscribe_create.py index ca8d0221e..358d8dd10 100644 --- a/tests/filter/test_subscribe_create.py +++ b/tests/filter/test_subscribe_create.py @@ -75,9 +75,10 @@ class TestFilterSubscribeCreate(StepsFilter): assert not failed_content_topics, f"ContentTopics failed: {failed_content_topics}" try: self.create_filter_subscription({"requestId": "1", "contentFilters": ["rate limited"], "pubsubTopic": self.test_pubsub_topic}) - raise AssertionError("The 30th subscribe call was not rate limited!!!") except Exception as ex: assert "subscription failed" in str(ex) or "rate limit exceeded" in str(ex) + else: + raise AssertionError("Expected extra filter subscription to be rate limited, but it succeeded") def test_filter_subscribe_to_101_content_topics(self, subscribe_main_nodes): try: