fix: cluster_id 0 for peer store related tests (#56)

* fix: use cluster_id 0 for peer store related tests

* test: simulation for issue

* fix: use cluster_id not 0 and subscribe to static shard for go-waku

* fix: revert env values to original defaults
This commit is contained in:
Roman Zajic 2024-07-15 15:47:42 +02:00 committed by GitHub
parent 03e577e558
commit 055541ad0d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 42 additions and 5 deletions

View File

@ -163,3 +163,26 @@ class StepsRelay(StepsCommon):
def subscribe_and_publish_with_retry(self, node_list, pubsub_topic_list):
self.ensure_relay_subscriptions_on_nodes(node_list, pubsub_topic_list)
self.check_published_message_reaches_relay_peer()
@allure.step
def setup_main_nodes(self, **kwargs):
self.node1 = WakuNode(NODE_1, f"node1_{self.test_id}")
self.node1.start(relay="true", nodekey=NODEKEY, **kwargs)
self.enr_uri = self.node1.get_enr_uri()
self.multiaddr_with_id = self.node1.get_multiaddr_with_id()
self.node2 = WakuNode(NODE_2, f"node2_{self.test_id}")
self.node2.start(relay="true", discv5_bootstrap_node=self.enr_uri, **kwargs)
self.add_node_peer(self.node2, [self.multiaddr_with_id])
self.main_nodes.extend([self.node1, self.node2])
@allure.step
def setup_optional_nodes(self, **kwargs):
if ADDITIONAL_NODES:
nodes = [node.strip() for node in ADDITIONAL_NODES.split(",")]
else:
pytest.skip("ADDITIONAL_NODES is empty, cannot run test")
for index, node in enumerate(nodes):
node = WakuNode(node, f"node{index + 3}_{self.test_id}")
node.start(relay="true", discv5_bootstrap_node=self.enr_uri, **kwargs)
self.add_node_peer(node, [self.multiaddr_with_id])
self.optional_nodes.append(node)

View File

@ -6,34 +6,41 @@ from src.libs.custom_logger import get_custom_logger
from src.node.waku_node import peer_info2id, peer_info2multiaddr, multiaddr2id
from src.steps.relay import StepsRelay
from src.steps.store import StepsStore
from src.test_data import VALID_PUBSUB_TOPICS
logger = get_custom_logger(__name__)
class TestPeerStore(StepsRelay, StepsStore):
@pytest.mark.usefixtures("setup_main_relay_nodes", "setup_optional_relay_nodes")
def test_get_peers(self):
self.setup_main_nodes()
self.setup_optional_nodes()
self.ensure_relay_subscriptions_on_nodes(self.main_nodes + self.optional_nodes, VALID_PUBSUB_TOPICS)
nodes = [self.node1, self.node2]
nodes.extend(self.optional_nodes)
delay(1)
delay(10)
ids = []
for node in nodes:
for i, node in enumerate(nodes):
node_id = node.get_id()
logger.debug(f"Node {i} peer ID {node_id}")
ids.append(node_id)
for i in range(5):
others = []
for peer_info in nodes[i].get_peers():
logger.debug(f"Node {i} peer info {peer_info}")
peer_id = peer_info2id(peer_info, nodes[i].is_nwaku())
others.append(peer_id)
assert (i == 0 and len(others) == 4) or (i > 0 and len(others) >= 1), f"Some nodes missing in the peer store of Node ID {ids[i]}"
@pytest.mark.usefixtures("setup_main_relay_nodes", "setup_optional_relay_nodes")
def test_add_peers(self):
self.setup_main_nodes()
self.setup_optional_nodes()
self.ensure_relay_subscriptions_on_nodes(self.main_nodes + self.optional_nodes, VALID_PUBSUB_TOPICS)
nodes = [self.node1, self.node2]
nodes.extend(self.optional_nodes)
delay(1)
delay(10)
peers_multiaddr = set()
for i in range(2):
for peer_info in nodes[i].get_peers():
@ -60,6 +67,7 @@ class TestPeerStore(StepsRelay, StepsStore):
def test_get_peers_two_protocols(self):
self.setup_first_publishing_node(store="true", relay="true")
self.setup_first_store_node(store="true", relay="false")
self.ensure_relay_subscriptions_on_nodes([self.publishing_node1, self.store_node1], VALID_PUBSUB_TOPICS)
delay(1)
node1_peers = self.publishing_node1.get_peers()
node2_peers = self.store_node1.get_peers()
@ -73,6 +81,7 @@ class TestPeerStore(StepsRelay, StepsStore):
def test_use_persistent_storage_survive_restart(self):
self.setup_first_relay_node(peer_persistence="true")
self.setup_second_relay_node()
self.ensure_relay_subscriptions_on_nodes(self.main_nodes, VALID_PUBSUB_TOPICS)
delay(1)
node1_peers = self.node1.get_peers()
node2_peers = self.node2.get_peers()
@ -94,6 +103,7 @@ class TestPeerStore(StepsRelay, StepsStore):
def test_peer_store_content_after_node2_restarts(self):
self.setup_first_relay_node()
self.setup_second_relay_node()
self.ensure_relay_subscriptions_on_nodes(self.main_nodes, VALID_PUBSUB_TOPICS)
delay(1)
node1_peers = self.node1.get_peers()
node2_peers = self.node2.get_peers()

View File

@ -3,6 +3,7 @@ from src.env_vars import NODE_2
from src.libs.common import delay
from src.node.waku_node import peer_info2multiaddr, multiaddr2id
from src.steps.peer_exchange import StepsPeerExchange
from src.test_data import VALID_PUBSUB_TOPICS
@pytest.mark.skipif("go-waku" not in NODE_2, reason="Test works only with go-waku as responder - https://github.com/waku-org/nwaku/issues/2875")
@ -10,6 +11,7 @@ class TestPeerExchange(StepsPeerExchange):
def test_get_peers_for_blank_node(self):
self.setup_first_relay_node(relay_peer_exchange="true")
self.setup_second_relay_node(peer_exchange="true")
self.ensure_relay_subscriptions_on_nodes(self.main_nodes, VALID_PUBSUB_TOPICS)
delay(1)
node1_peers = self.node1.get_peers()
assert len(node1_peers) == 1
@ -28,6 +30,7 @@ class TestPeerExchange(StepsPeerExchange):
def test_get_peers_for_filter_node(self):
self.setup_first_relay_node(filter="true", relay_peer_exchange="true")
self.setup_second_relay_node(filter="true", peer_exchange="true")
self.ensure_relay_subscriptions_on_nodes(self.main_nodes, VALID_PUBSUB_TOPICS)
delay(1)
node1_peers = self.node1.get_peers()
assert len(node1_peers) == 1
@ -46,6 +49,7 @@ class TestPeerExchange(StepsPeerExchange):
def test_get_peers_after_node1_was_restarted(self):
self.setup_first_relay_node(relay_peer_exchange="true")
self.setup_second_relay_node(peer_exchange="true")
self.ensure_relay_subscriptions_on_nodes(self.main_nodes, VALID_PUBSUB_TOPICS)
delay(1)
node1_peers = self.node1.get_peers()
assert len(node1_peers) == 1