From dd140dcb744d7ca7322daacdfc42727c6e7717c8 Mon Sep 17 00:00:00 2001 From: Florin Barbu Date: Thu, 7 Mar 2024 14:36:53 +0200 Subject: [PATCH] small fixes (#20) * small fixes * adjustments * xfail test --- src/node/api_clients/rest.py | 4 ++++ src/node/waku_node.py | 3 +++ src/steps/filter.py | 12 +++++++----- src/steps/relay.py | 12 +++++++----- tests/filter/test_multiple_nodes.py | 5 +++-- 5 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/node/api_clients/rest.py b/src/node/api_clients/rest.py index 10268db6a5..e13f96dd45 100644 --- a/src/node/api_clients/rest.py +++ b/src/node/api_clients/rest.py @@ -19,6 +19,10 @@ class REST(BaseClient): info_response = self.rest_call("get", "debug/v1/info") return info_response.json() + def get_peers(self): + info_response = self.rest_call("get", "admin/v1/peers") + return info_response.json() + def set_relay_subscriptions(self, pubsub_topics): return self.rest_call("post", "relay/v1/subscriptions", json.dumps(pubsub_topics)) diff --git a/src/node/waku_node.py b/src/node/waku_node.py index 8acae3d35d..39c97deea4 100644 --- a/src/node/waku_node.py +++ b/src/node/waku_node.py @@ -209,6 +209,9 @@ class WakuNode: def info(self): return self._api.info() + def get_peers(self): + return self._api.get_peers() + def set_relay_subscriptions(self, pubsub_topics): return self._api.set_relay_subscriptions(pubsub_topics) diff --git a/src/steps/filter.py b/src/steps/filter.py index 3683dfee9f..33171b9b31 100644 --- a/src/steps/filter.py +++ b/src/steps/filter.py @@ -71,7 +71,7 @@ class StepsFilter: else: pytest.skip("ADDITIONAL_NODES/node_list is empty, cannot run test") for index, node in enumerate(nodes): - node = WakuNode(node, f"additional_node{index + 1}_{self.test_id}") + node = WakuNode(node, f"node{index + 3}_{self.test_id}") node.start(relay="false", filter="true", discv5_bootstrap_node=self.enr_uri, filternode=self.multiaddr_with_id) self.optional_nodes.append(node) @@ -91,9 +91,9 @@ class StepsFilter: sender.send_relay_message(message, pubsub_topic) delay(message_propagation_delay) for index, peer in enumerate(peer_list): - logger.debug(f"Checking that peer NODE_{index + 1}:{peer.image} can find the published message") + logger.debug(f"Checking that peer NODE_{index + 2}:{peer.image} can find the published message") get_messages_response = self.get_filter_messages(message["contentTopic"], pubsub_topic=pubsub_topic, node=peer) - assert get_messages_response, f"Peer NODE_{index + 1}:{peer.image} couldn't find any messages" + assert get_messages_response, f"Peer NODE_{index + 2}:{peer.image} couldn't find any messages" assert len(get_messages_response) == 1, f"Expected 1 message but got {len(get_messages_response)}" waku_message = WakuMessage(get_messages_response) waku_message.assert_received_message(message) @@ -107,11 +107,13 @@ class StepsFilter: assert "Bad Request" in str(ex) or "Not Found" in str(ex) or "couldn't find any messages" in str(ex) @allure.step - def wait_for_published_message_to_reach_filter_peer(self, timeout_duration=120, time_between_retries=1, pubsub_topic=None, peer_list=None): + def wait_for_published_message_to_reach_filter_peer( + self, timeout_duration=120, time_between_retries=1, pubsub_topic=None, sender=None, peer_list=None + ): @retry(stop=stop_after_delay(timeout_duration), wait=wait_fixed(time_between_retries), reraise=True) def publish_and_check_filter_peer(): message = {"payload": to_base64(self.test_payload), "contentTopic": self.test_content_topic, "timestamp": int(time() * 1e9)} - self.check_publish_without_filter_subscription(message, pubsub_topic=pubsub_topic, peer_list=peer_list) + self.check_published_message_reaches_filter_peer(message, pubsub_topic=pubsub_topic, sender=sender, peer_list=peer_list) publish_and_check_filter_peer() diff --git a/src/steps/relay.py b/src/steps/relay.py index 753bd5343e..cd9471e8b7 100644 --- a/src/steps/relay.py +++ b/src/steps/relay.py @@ -57,10 +57,12 @@ class StepsRelay: def setup_main_rln_relay_nodes(self, request): logger.debug(f"Running fixture setup: {inspect.currentframe().f_code.co_name}") self.node1 = WakuNode(DEFAULT_NWAKU, f"node1_{request.cls.test_id}") - self.node1.start(relay="true", nodekey=NODEKEY, rln_creds_source=RLN_CREDENTIALS, rln_creds_id="1") + self.node1.start(relay="true", nodekey=NODEKEY, rln_creds_source=RLN_CREDENTIALS, rln_creds_id="1", rln_relay_membership_index="1") self.enr_uri = self.node1.get_enr_uri() self.node2 = WakuNode(DEFAULT_NWAKU, f"node2_{request.cls.test_id}") - self.node2.start(relay="true", discv5_bootstrap_node=self.enr_uri, rln_creds_source=RLN_CREDENTIALS, rln_creds_id="2") + self.node2.start( + relay="true", discv5_bootstrap_node=self.enr_uri, rln_creds_source=RLN_CREDENTIALS, rln_creds_id="2", rln_relay_membership_index="1" + ) self.main_nodes.extend([self.node1, self.node2]) @pytest.fixture(scope="function") @@ -71,7 +73,7 @@ class StepsRelay: else: pytest.skip("ADDITIONAL_NODES is empty, cannot run test") for index, node in enumerate(nodes): - node = WakuNode(node, f"additional_node{index}_{request.cls.test_id}") + node = WakuNode(node, f"node{index + 3}_{request.cls.test_id}") node.start(relay="true", discv5_bootstrap_node=self.enr_uri) self.optional_nodes.append(node) @@ -109,9 +111,9 @@ class StepsRelay: sender.send_relay_message(message, pubsub_topic) delay(message_propagation_delay) for index, peer in enumerate(peer_list): - logger.debug(f"Checking that peer NODE_{index + 1}:{peer.image} can find the published message") + logger.debug(f"Checking that peer NODE_{index + 2}:{peer.image} can find the published message") get_messages_response = peer.get_relay_messages(pubsub_topic) - assert get_messages_response, f"Peer NODE_{index + 1}:{peer.image} couldn't find any messages" + assert get_messages_response, f"Peer NODE_{index + 2}:{peer.image} couldn't find any messages" assert len(get_messages_response) == 1, f"Expected 1 message but got {len(get_messages_response)}" waku_message = WakuMessage(get_messages_response) waku_message.assert_received_message(message) diff --git a/tests/filter/test_multiple_nodes.py b/tests/filter/test_multiple_nodes.py index 2bd0288a85..c6b99d2e98 100644 --- a/tests/filter/test_multiple_nodes.py +++ b/tests/filter/test_multiple_nodes.py @@ -1,5 +1,5 @@ import pytest -from src.env_vars import NODE_1 +from src.env_vars import NODE_1, NODE_2 from src.libs.common import delay from src.libs.custom_logger import get_custom_logger from src.steps.filter import StepsFilter @@ -9,11 +9,12 @@ logger = get_custom_logger(__name__) @pytest.mark.usefixtures("setup_main_relay_node", "setup_main_filter_node") class TestFilterMultipleNodes(StepsFilter): + @pytest.mark.xfail("nwaku" in NODE_2, reason="Bug reported: https://github.com/waku-org/nwaku/issues/2512") def test_all_nodes_subscribed_to_the_topic(self): self.setup_optional_filter_nodes() self.wait_for_subscriptions_on_main_nodes([self.test_content_topic]) self.subscribe_optional_filter_nodes([self.test_content_topic]) - self.wait_for_published_message_to_reach_filter_peer() + self.check_published_message_reaches_filter_peer() def test_optional_nodes_not_subscribed_to_same_topic(self): self.setup_optional_filter_nodes()