new tests

This commit is contained in:
fbarbu15 2023-11-23 10:24:21 +02:00
parent f5dcdd70a7
commit b84252c581
No known key found for this signature in database
GPG Key ID: D75221C8DEA22501
4 changed files with 36 additions and 15 deletions

View File

@ -65,13 +65,16 @@ class StepsRelay:
# this method should be used only for the tests that use the warm_up fixture
# otherwise use wait_for_published_message_to_reach_peer
@allure.step
def check_published_message_reaches_peer(self, message, pubsub_topic=None, message_propagation_delay=0.1, sender=None, peer_list=None):
def check_published_message_reaches_peer(self, message=None, pubsub_topic=None, message_propagation_delay=0.1, sender=None, peer_list=None):
if message is None:
message = self.create_message()
if pubsub_topic is None:
pubsub_topic = self.test_pubsub_topic
if not sender:
sender = self.node1
if not peer_list:
peer_list = self.main_nodes + self.optional_nodes
if pubsub_topic is None:
pubsub_topic = self.test_pubsub_topic
sender.send_message(message, pubsub_topic)
delay(message_propagation_delay)
for index, peer in enumerate(peer_list):
@ -84,7 +87,7 @@ class StepsRelay:
@allure.step
def check_publish_without_subscription(self, pubsub_topic):
try:
self.check_published_message_reaches_peer(self.create_message(), pubsub_topic=pubsub_topic)
self.node1.send_message(self.create_message(), pubsub_topic)
raise AssertionError("Publish with no subscription worked!!!")
except Exception as ex:
assert "Bad Request" in str(ex) or "Internal Server Error" in str(ex)

View File

@ -5,15 +5,15 @@ from src.steps.relay import StepsRelay
@pytest.mark.usefixtures("setup_main_relay_nodes", "setup_optional_relay_nodes", "subscribe_main_relay_nodes")
class TestMultipleNodes(StepsRelay):
def test_first_node_to_start_publishes(self, subscribe_optional_relay_nodes, relay_warm_up):
self.check_published_message_reaches_peer(self.create_message())
self.check_published_message_reaches_peer()
def test_last_node_to_start_publishes(self, subscribe_optional_relay_nodes, relay_warm_up):
self.check_published_message_reaches_peer(self.create_message(), sender=self.optional_nodes[-1])
self.check_published_message_reaches_peer(sender=self.optional_nodes[-1])
def test_optional_nodes_not_subscribed_to_same_pubsub_topic(self):
self.wait_for_published_message_to_reach_peer(peer_list=self.main_nodes)
try:
self.check_published_message_reaches_peer(self.create_message(), peer_list=self.optional_nodes)
self.check_published_message_reaches_peer(peer_list=self.optional_nodes)
raise AssertionError("Non subscribed nodes received the message!!")
except Exception as ex:
assert "Not Found" in str(ex), "Expected 404 Not Found when the message is not found"

View File

@ -97,7 +97,7 @@ class TestRelayPublish(StepsRelay):
for pubsub_topic in VALID_PUBSUB_TOPICS:
logger.debug(f"Running test with pubsub topic {pubsub_topic}")
try:
self.check_published_message_reaches_peer(self.create_message(), pubsub_topic=pubsub_topic)
self.check_published_message_reaches_peer(pubsub_topic=pubsub_topic)
except Exception as e:
logger.error(f"PubusubTopic {pubsub_topic} failed: {str(e)}")
failed_pubsub_topics.append(pubsub_topic)
@ -112,7 +112,7 @@ class TestRelayPublish(StepsRelay):
def test_publish_on_non_subscribed_pubsub_topic(self):
try:
self.check_published_message_reaches_peer(self.create_message(), pubsub_topic="/waku/2/rs/19/1")
self.check_published_message_reaches_peer(pubsub_topic="/waku/2/rs/19/1")
raise AssertionError("Publish on unsubscribed pubsub_topic worked!!!")
except Exception as ex:
assert "Bad Request" in str(ex) or "Internal Server Error" in str(ex)
@ -209,7 +209,7 @@ class TestRelayPublish(StepsRelay):
self.assert_received_message(message, received_message)
def test_publish_after_node_pauses_and_pauses(self):
self.check_published_message_reaches_peer(self.create_message())
self.check_published_message_reaches_peer()
self.node1.pause()
self.node1.unpause()
self.check_published_message_reaches_peer(self.create_message(payload=to_base64("M1")))
@ -218,14 +218,14 @@ class TestRelayPublish(StepsRelay):
self.check_published_message_reaches_peer(self.create_message(payload=to_base64("M2")))
def test_publish_after_node1_restarts(self):
self.check_published_message_reaches_peer(self.create_message())
self.check_published_message_reaches_peer()
self.node1.restart()
self.node1.ensure_ready()
self.ensure_subscriptions_on_nodes(self.main_nodes, [self.test_pubsub_topic])
self.wait_for_published_message_to_reach_peer()
def test_publish_after_node2_restarts(self):
self.check_published_message_reaches_peer(self.create_message())
self.check_published_message_reaches_peer()
self.node2.restart()
self.node2.ensure_ready()
self.ensure_subscriptions_on_nodes(self.main_nodes, [self.test_pubsub_topic])

View File

@ -1,4 +1,5 @@
import pytest
from src.env_vars import DEFAULT_PUBSUB_TOPIC
from src.libs.custom_logger import get_custom_logger
from src.steps.relay import StepsRelay
from src.test_data import INVALID_PUBSUB_TOPICS, VALID_PUBSUB_TOPICS
@ -19,7 +20,7 @@ class TestRelaySubscribe(StepsRelay):
self.ensure_subscriptions_on_nodes(self.main_nodes, [self.test_pubsub_topic])
self.wait_for_published_message_to_reach_peer()
self.ensure_subscriptions_on_nodes(self.main_nodes, [self.test_pubsub_topic])
self.check_published_message_reaches_peer(self.create_message())
self.check_published_message_reaches_peer()
def test_subscribe_with_multiple_overlapping_pubsub_topics(self):
self.ensure_subscriptions_on_nodes(self.main_nodes, VALID_PUBSUB_TOPICS[:3])
@ -63,7 +64,7 @@ class TestRelaySubscribe(StepsRelay):
for pubsub_topic in VALID_PUBSUB_TOPICS[:3]:
self.check_publish_without_subscription(pubsub_topic)
for pubsub_topic in VALID_PUBSUB_TOPICS[3:]:
self.check_published_message_reaches_peer(self.create_message(), pubsub_topic=pubsub_topic)
self.check_published_message_reaches_peer(pubsub_topic=pubsub_topic)
def test_unsubscribe_from_non_existing_pubsub_topic(self):
self.ensure_subscriptions_on_nodes(self.main_nodes, [self.test_pubsub_topic])
@ -78,7 +79,7 @@ class TestRelaySubscribe(StepsRelay):
raise Exception("Not implemented")
except Exception as ex:
assert "Bad Request" in str(ex) or "Internal Server Error" in str(ex)
self.check_published_message_reaches_peer(self.create_message())
self.check_published_message_reaches_peer()
def test_unsubscribe_with_invalid_pubsub_topic_format(self):
success_pubsub_topics = []
@ -90,3 +91,20 @@ class TestRelaySubscribe(StepsRelay):
except Exception as ex:
assert "Bad Request" in str(ex)
assert not success_pubsub_topics, f"Invalid Pubsub Topics that didn't failed: {success_pubsub_topics}"
def test_resubscribe_to_unsubscribed_pubsub_topic(self):
self.ensure_subscriptions_on_nodes(self.main_nodes, [self.test_pubsub_topic])
self.wait_for_published_message_to_reach_peer()
self.delete_subscriptions_on_nodes(self.main_nodes, [self.test_pubsub_topic])
self.check_publish_without_subscription(self.test_pubsub_topic)
self.ensure_subscriptions_on_nodes(self.main_nodes, [self.test_pubsub_topic])
self.check_published_message_reaches_peer()
def test_publish_on_default_pubsub_topic_without_beeing_subscribed_to_it(self):
self.ensure_subscriptions_on_nodes(self.main_nodes, [self.test_pubsub_topic])
self.wait_for_published_message_to_reach_peer()
try:
self.check_published_message_reaches_peer(pubsub_topic=DEFAULT_PUBSUB_TOPIC)
raise AssertionError(f"Publish on {DEFAULT_PUBSUB_TOPIC} with beeing subscribed to it worked!!!")
except Exception as ex:
assert "Not Found" in str(ex)