diff --git a/src/env_vars.py b/src/env_vars.py index 0824fc69..abf923a9 100644 --- a/src/env_vars.py +++ b/src/env_vars.py @@ -14,8 +14,8 @@ def get_env_var(var_name, default=None): # Configuration constants. Need to be upercase to appear in reports -NODE_1 = get_env_var("NODE_1", "wakuorg/nwaku:latest") -NODE_2 = get_env_var("NODE_2", "wakuorg/go-waku:latest") +NODE_1 = get_env_var("NODE_1", "wakuorg/go-waku:latest") +NODE_2 = get_env_var("NODE_2", "wakuorg/nwaku:latest") DOCKER_LOG_DIR = get_env_var("DOCKER_LOG_DIR", "./log/docker") NETWORK_NAME = get_env_var("NETWORK_NAME", "waku") SUBNET = get_env_var("SUBNET", "172.18.0.0/16") diff --git a/src/node/waku_node.py b/src/node/waku_node.py index d3fa437a..1867d01d 100644 --- a/src/node/waku_node.py +++ b/src/node/waku_node.py @@ -86,6 +86,21 @@ class WakuNode: self._container.stop() logger.debug("Container stopped.") + def restart(self): + if self._container: + logger.debug("Restarting container with id %s", self._container.short_id) + self._container.restart() + + def pause(self): + if self._container: + logger.debug("Pausing container with id %s", self._container.short_id) + self._container.pause() + + def unpause(self): + if self._container: + logger.debug("Unpause container with id %s", self._container.short_id) + self._container.unpause() + @retry(stop=stop_after_delay(10), wait=wait_fixed(0.1), reraise=True) def ensure_ready(self): self.info() diff --git a/src/steps/relay.py b/src/steps/relay.py index f67f602b..3b96db47 100644 --- a/src/steps/relay.py +++ b/src/steps/relay.py @@ -28,11 +28,9 @@ class StepsRelay: self.node2.set_subscriptions([self.test_pubsub_topic]) @pytest.fixture(scope="function", autouse=True) - @retry(stop=stop_after_delay(120), wait=wait_fixed(1), reraise=True) - def wait_for_network_to_warm_up(self): - message = {"payload": to_base64(self.test_payload), "contentTopic": self.test_content_topic, "timestamp": int(time() * 1e9)} + def network_warm_up(self, setup_nodes): try: - self.check_published_message_reaches_peer(message) + self.wait_for_published_message_to_reach_peer(120) logger.info("WARM UP successful !!") except Exception as ex: raise Exception(f"WARM UP FAILED WITH: {ex}") @@ -73,3 +71,11 @@ class StepsRelay: assert str(received_message.ephemeral) == str(sent_message["ephemeral"]), assert_fail_message("ephemeral") if "rateLimitProof" in sent_message and sent_message["rateLimitProof"]: assert str(received_message.rateLimitProof) == str(sent_message["rateLimitProof"]), assert_fail_message("rateLimitProof") + + def wait_for_published_message_to_reach_peer(self, timeout_duration, time_between_retries=1): + @retry(stop=stop_after_delay(timeout_duration), wait=wait_fixed(time_between_retries), reraise=True) + def check_peer_connection(): + message = {"payload": to_base64(self.test_payload), "contentTopic": self.test_content_topic, "timestamp": int(time() * 1e9)} + self.check_published_message_reaches_peer(message) + + check_peer_connection() diff --git a/tests/relay/test_publish.py b/tests/relay/test_publish.py index 11c55556..c286a73e 100644 --- a/tests/relay/test_publish.py +++ b/tests/relay/test_publish.py @@ -1,8 +1,9 @@ from src.libs.custom_logger import get_custom_logger -from time import time +from time import sleep, time from src.libs.common import to_base64 from src.steps.relay import StepsRelay from src.test_data import INVALID_CONTENT_TOPICS, INVALID_PAYLOADS, SAMPLE_INPUTS, SAMPLE_TIMESTAMPS +import pytest logger = get_custom_logger(__name__) @@ -150,14 +151,6 @@ class TestRelayPublish(StepsRelay): except Exception as ex: assert "Bad Request" in str(ex) - def test_publish_with_rate_limit_proof(self): - self.test_message["rateLimitProof"] = { - "proof": to_base64("proofData"), - "epoch": to_base64("epochData"), - "nullifier": to_base64("nullifierData"), - } - self.check_published_message_reaches_peer(self.test_message) - def test_publish_with_ephemeral(self): failed_ephemeral = [] for ephemeral in [True, False]: @@ -170,6 +163,18 @@ class TestRelayPublish(StepsRelay): failed_ephemeral.append(ephemeral) assert not failed_ephemeral, f"Ephemeral that failed: {failed_ephemeral}" + def test_publish_with_rate_limit_proof(self): + self.test_message["rateLimitProof"] = { + "proof": to_base64("proofData"), + "epoch": to_base64("epochData"), + "nullifier": to_base64("nullifierData"), + } + self.check_published_message_reaches_peer(self.test_message) + + def test_publish_with_extra_field(self): + self.test_message["extraField"] = "extraValue" + self.check_published_message_reaches_peer(self.test_message) + def test_publish_and_retrieve_duplicate_message(self): self.check_published_message_reaches_peer(self.test_message) try: @@ -177,3 +182,29 @@ class TestRelayPublish(StepsRelay): raise AssertionError("Duplicate message was retrieved twice") except Exception as ex: assert "Peer node couldn't find any messages" in str(ex) + + def test_publish_after_node_pauses(self): + self.check_published_message_reaches_peer(self.test_message) + self.node1.pause() + self.node1.unpause() + self.test_message["payload"] = to_base64("new payload 1") + self.check_published_message_reaches_peer(self.test_message) + self.node2.pause() + self.node2.unpause() + self.test_message["payload"] = to_base64("new payload 2") + self.check_published_message_reaches_peer(self.test_message) + + @pytest.mark.skip("enrUri resets after node restart and node2 looses connection") + def test_publish_after_node1_restarts(self): + self.check_published_message_reaches_peer(self.test_message) + self.node1.restart() + self.node1.set_subscriptions([self.test_pubsub_topic]) + self.node2.set_subscriptions([self.test_pubsub_topic]) + self.wait_for_published_message_to_reach_peer(20) + + def test_publish_after_node2_restarts(self): + self.check_published_message_reaches_peer(self.test_message) + self.node2.restart() + self.node1.set_subscriptions([self.test_pubsub_topic]) + self.node2.set_subscriptions([self.test_pubsub_topic]) + self.wait_for_published_message_to_reach_peer(20)