From e419b7f8a6db88d20545297d17cc79d6753c4554 Mon Sep 17 00:00:00 2001 From: AYAHASSAN287 <49167455+AYAHASSAN287@users.noreply.github.com> Date: Mon, 28 Oct 2024 12:30:40 +0300 Subject: [PATCH 1/3] Waku edge tests all (#81) * Adding function to calculate different time variants exclude 5 tests for go-waku * change second node to nwaku * skip 2 tests failed for go-waku * change node_2 back to nwaku * skipping failed test for nwaku * remove the skipping for nwaku node as requested --- src/steps/common.py | 19 ++++++ tests/light_push/test_publish.py | 2 +- tests/store/test_api_flags.py | 3 +- tests/store/test_page_size.py | 2 + tests/store/test_time_filter.py | 104 ++++++++++++++++--------------- 5 files changed, 78 insertions(+), 52 deletions(-) diff --git a/src/steps/common.py b/src/steps/common.py index dbb06bb599..f09433209a 100644 --- a/src/steps/common.py +++ b/src/steps/common.py @@ -4,6 +4,7 @@ import inspect from time import time import allure import pytest +from datetime import timedelta, datetime from tenacity import retry, stop_after_delay, wait_fixed from src.libs.common import delay, to_base64 from src.libs.custom_logger import get_custom_logger @@ -57,3 +58,21 @@ class StepsCommon: ctx.update(int(msg["timestamp"]).to_bytes(8, byteorder="big")) hash_bytes = ctx.digest() return base64.b64encode(hash_bytes).decode("utf-8") + + def get_time_list_pass(self): + ts_pass = [ + {"description": "3 sec Past", "value": int((datetime.now() - timedelta(seconds=3)).timestamp() * 1e9)}, + {"description": "1 sec Past", "value": int((datetime.now() - timedelta(seconds=1)).timestamp() * 1e9)}, + {"description": "0.1 sec Past", "value": int((datetime.now() - timedelta(seconds=0.1)).timestamp() * 1e9)}, + {"description": "0.1 sec Future", "value": int((datetime.now() + timedelta(seconds=0.1)).timestamp() * 1e9)}, + {"description": "2 sec Future", "value": int((datetime.now() + timedelta(seconds=2)).timestamp() * 1e9)}, + {"description": "10 sec Future", "value": int((datetime.now() + timedelta(seconds=10)).timestamp() * 1e9)}, + ] + return ts_pass + + def get_time_list_fail(self): + ts_fail = [ + {"description": "20 sec Past", "value": int((datetime.now() - timedelta(seconds=20)).timestamp() * 1e9)}, + {"description": "40 sec Future", "value": int((datetime.now() + timedelta(seconds=40)).timestamp() * 1e9)}, + ] + return ts_fail diff --git a/tests/light_push/test_publish.py b/tests/light_push/test_publish.py index 8777fe5ca9..0d3aebcd81 100644 --- a/tests/light_push/test_publish.py +++ b/tests/light_push/test_publish.py @@ -1,5 +1,5 @@ import pytest -from src.env_vars import NODE_2 + from src.libs.custom_logger import get_custom_logger from time import time from src.libs.common import delay, to_base64 diff --git a/tests/store/test_api_flags.py b/tests/store/test_api_flags.py index 35ce168d88..0e298b3706 100644 --- a/tests/store/test_api_flags.py +++ b/tests/store/test_api_flags.py @@ -1,5 +1,5 @@ import pytest -from time import time +from src.env_vars import NODE_1, NODE_2 from src.libs.custom_logger import get_custom_logger from src.libs.common import to_base64 from src.node.waku_message import WakuMessage @@ -17,6 +17,7 @@ class TestApiFlags(StepsStore): self.publish_message() self.check_published_message_is_stored(store_node=self.store_node1, peer_addr=self.multiaddr_list[0]) + @pytest.mark.skipif("go-waku" in (NODE_1 + NODE_2), reason="Test works only with nwaku") def test_store_with_wrongPeerAddr(self): self.publish_message() wrong_peer_addr = self.multiaddr_list[0][1:] diff --git a/tests/store/test_page_size.py b/tests/store/test_page_size.py index 0d7fe7bb14..7df706eff6 100644 --- a/tests/store/test_page_size.py +++ b/tests/store/test_page_size.py @@ -1,4 +1,5 @@ import pytest +from src.env_vars import NODE_1, NODE_2 from src.libs.common import to_base64 from src.steps.store import StepsStore from src.libs.custom_logger import get_custom_logger @@ -44,6 +45,7 @@ class TestPageSize(StepsStore): store_response = self.get_messages_from_store(node, page_size=1000000) assert len(store_response.messages) == 100, "Message count mismatch" + @pytest.mark.skipif("go-waku" in (NODE_1 + NODE_2), reason="Test works only with nwaku") def test_negative_number_page_size(self): page_size = -1 for i in range(10): diff --git a/tests/store/test_time_filter.py b/tests/store/test_time_filter.py index b50735e1b4..d59e122b41 100644 --- a/tests/store/test_time_filter.py +++ b/tests/store/test_time_filter.py @@ -1,5 +1,5 @@ import time - +from src.env_vars import NODE_1, NODE_2 import pytest from datetime import timedelta, datetime from src.libs.custom_logger import get_custom_logger @@ -10,24 +10,10 @@ logger = get_custom_logger(__name__) @pytest.mark.usefixtures("node_setup") class TestTimeFilter(StepsStore): - @pytest.fixture(scope="function", autouse=True) - def setup_test_data(self): - self.ts_pass = [ - {"description": "3 sec Past", "value": int((datetime.now() - timedelta(seconds=3)).timestamp() * 1e9)}, - {"description": "1 sec Past", "value": int((datetime.now() - timedelta(seconds=1)).timestamp() * 1e9)}, - {"description": "0.1 sec Past", "value": int((datetime.now() - timedelta(seconds=0.1)).timestamp() * 1e9)}, - {"description": "0.1 sec Future", "value": int((datetime.now() + timedelta(seconds=0.1)).timestamp() * 1e9)}, - {"description": "2 sec Future", "value": int((datetime.now() + timedelta(seconds=2)).timestamp() * 1e9)}, - {"description": "10 sec Future", "value": int((datetime.now() + timedelta(seconds=10)).timestamp() * 1e9)}, - ] - self.ts_fail = [ - {"description": "20 sec Past", "value": int((datetime.now() - timedelta(seconds=20)).timestamp() * 1e9)}, - {"description": "40 sec Future", "value": int((datetime.now() + timedelta(seconds=40)).timestamp() * 1e9)}, - ] - def test_messages_with_timestamps_close_to_now(self): failed_timestamps = [] - for timestamp in self.ts_pass: + ts_pass = self.get_time_list_pass() + for timestamp in ts_pass: logger.debug(f'Running test with payload {timestamp["description"]}') message = self.create_message(timestamp=timestamp["value"]) try: @@ -40,7 +26,8 @@ class TestTimeFilter(StepsStore): def test_messages_with_timestamps_far_from_now(self): success_timestamps = [] - for timestamp in self.ts_fail: + ts_fail = self.get_time_list_fail() + for timestamp in ts_fail: logger.debug(f'Running test with payload {timestamp["description"]}') message = self.create_message(timestamp=timestamp["value"]) try: @@ -53,7 +40,8 @@ class TestTimeFilter(StepsStore): def test_time_filter_matches_one_message(self): message_hash_list = [] - for timestamp in self.ts_pass: + ts_pass = self.get_time_list_pass() + for timestamp in ts_pass: message = self.create_message(timestamp=timestamp["value"]) self.publish_message(message=message) message_hash_list.append(self.compute_message_hash(self.test_pubsub_topic, message)) @@ -61,15 +49,16 @@ class TestTimeFilter(StepsStore): store_response = self.get_messages_from_store( node, page_size=20, - start_time=self.ts_pass[0]["value"] - 100000, - end_time=self.ts_pass[0]["value"] + 100000, + start_time=ts_pass[0]["value"] - 100000, + end_time=ts_pass[0]["value"] + 100000, ) assert len(store_response.messages) == 1, "Message count mismatch" assert store_response.message_hash(0) == message_hash_list[0], "Incorrect messaged filtered based on time" def test_time_filter_matches_multiple_messages(self): message_hash_list = [] - for timestamp in self.ts_pass: + ts_pass = self.get_time_list_pass() + for timestamp in ts_pass: message = self.create_message(timestamp=timestamp["value"]) self.publish_message(message=message) message_hash_list.append(self.compute_message_hash(self.test_pubsub_topic, message)) @@ -77,8 +66,8 @@ class TestTimeFilter(StepsStore): store_response = self.get_messages_from_store( node, page_size=20, - start_time=self.ts_pass[0]["value"] - 100000, - end_time=self.ts_pass[4]["value"] + 100000, + start_time=ts_pass[0]["value"] - 100000, + end_time=ts_pass[4]["value"] + 100000, ) assert len(store_response.messages) == 5, "Message count mismatch" for i in range(5): @@ -86,7 +75,8 @@ class TestTimeFilter(StepsStore): def test_time_filter_matches_no_message(self): message_hash_list = [] - for timestamp in self.ts_pass: + ts_pass = self.get_time_list_pass() + for timestamp in ts_pass: message = self.create_message(timestamp=timestamp["value"]) self.publish_message(message=message) message_hash_list.append(self.compute_message_hash(self.test_pubsub_topic, message)) @@ -94,14 +84,15 @@ class TestTimeFilter(StepsStore): store_response = self.get_messages_from_store( node, page_size=20, - start_time=self.ts_pass[0]["value"] - 100000, - end_time=self.ts_pass[0]["value"] - 100, + start_time=ts_pass[0]["value"] - 100000, + end_time=ts_pass[0]["value"] - 100, ) assert not store_response.messages, "Message count mismatch" def test_time_filter_start_time_equals_end_time(self): message_hash_list = [] - for timestamp in self.ts_pass: + ts_pass = self.get_time_list_pass() + for timestamp in ts_pass: message = self.create_message(timestamp=timestamp["value"]) self.publish_message(message=message) message_hash_list.append(self.compute_message_hash(self.test_pubsub_topic, message)) @@ -109,16 +100,18 @@ class TestTimeFilter(StepsStore): store_response = self.get_messages_from_store( node, page_size=20, - start_time=self.ts_pass[0]["value"], - end_time=self.ts_pass[0]["value"], + start_time=ts_pass[0]["value"], + end_time=ts_pass[0]["value"], ) assert len(store_response.messages) == 1, "Message count mismatch" assert store_response.message_hash(0) == message_hash_list[0], "Incorrect messaged filtered based on time" + @pytest.mark.skipif("go-waku" in (NODE_1 + NODE_2), reason="Test works only with nwaku") def test_time_filter_start_time_after_end_time(self): - start_time = self.ts_pass[4]["value"] # 2 sec Future - end_time = self.ts_pass[0]["value"] # 3 sec past - for timestamp in self.ts_pass: + ts_pass = self.get_time_list_pass() + start_time = ts_pass[4]["value"] # 2 sec Future + end_time = ts_pass[0]["value"] # 3 sec past + for timestamp in ts_pass: message = self.create_message(timestamp=timestamp["value"]) self.publish_message(message=message) logger.debug(f"inquering stored messages with start time {start_time} after end time {end_time}") @@ -133,7 +126,8 @@ class TestTimeFilter(StepsStore): assert len(store_response.messages) == 0, "got messages with start time after end time !" def test_time_filter_negative_start_time(self): - for timestamp in self.ts_pass: + ts_pass = self.get_time_list_pass() + for timestamp in ts_pass: message = self.create_message(timestamp=timestamp["value"]) self.publish_message(message=message) @@ -146,7 +140,8 @@ class TestTimeFilter(StepsStore): assert len(store_response.messages) == 6, "number of messages retrieved doesn't match time filter " def test_time_filter_zero_start_time(self): - for timestamp in self.ts_pass: + ts_pass = self.get_time_list_pass() + for timestamp in ts_pass: message = self.create_message(timestamp=timestamp["value"]) self.publish_message(message=message) start_time = 0 @@ -157,8 +152,10 @@ class TestTimeFilter(StepsStore): assert len(store_response.messages) == 6, "number of messages retrieved doesn't match time filter " + @pytest.mark.skipif("go-waku" in (NODE_1 + NODE_2), reason="Test works only with nwaku") def test_time_filter_zero_start_end_time(self): - for timestamp in self.ts_pass: + ts_pass = self.get_time_list_pass() + for timestamp in ts_pass: message = self.create_message(timestamp=timestamp["value"]) self.publish_message(message=message) start_time = 0 @@ -171,7 +168,8 @@ class TestTimeFilter(StepsStore): assert len(store_response.messages) == 6, "number of messages retrieved doesn't match time filter " def test_time_filter_invalid_start_time(self): - for timestamp in self.ts_pass: + ts_pass = self.get_time_list_pass() + for timestamp in ts_pass: message = self.create_message(timestamp=timestamp["value"]) self.publish_message(message=message) start_time = "abc" @@ -185,23 +183,23 @@ class TestTimeFilter(StepsStore): assert e.args[0].find("Bad Request for url"), "url with wrong start_time is accepted" def test_time_filter_end_time_now(self): - self.ts_pass[3]["value"] = int((datetime.now() + timedelta(seconds=4)).timestamp() * 1e9) - start_time = self.ts_pass[0]["value"] - i = 0 - for timestamp in self.ts_pass: + ts_pass = self.get_time_list_pass() + ts_pass[3]["value"] = int((datetime.now() + timedelta(seconds=4)).timestamp() * 1e9) + start_time = ts_pass[0]["value"] + for timestamp in ts_pass: message = self.create_message(timestamp=timestamp["value"]) self.publish_message(message=message) - i += 1 end_time = int(datetime.now().timestamp() * 1e9) logger.debug(f"inquering stored messages with start time {start_time} after end time {end_time}") for node in self.store_nodes: store_response = self.get_messages_from_store(node, page_size=20, start_time=start_time, end_time=end_time, include_data=True) logger.debug(f"number of messages stored for start time {start_time} and " f"end time = {end_time} is {len(store_response.messages)}") - assert len(store_response.messages) == 4, "number of messages retrieved doesn't match time filter " + assert len(store_response.messages) == 3, "number of messages retrieved doesn't match time filter " def test_time_filter_big_timestamp(self): - start_time = self.ts_pass[0]["value"] - for timestamp in self.ts_pass: + ts_pass = self.get_time_list_pass() + start_time = ts_pass[0]["value"] + for timestamp in ts_pass: message = self.create_message(timestamp=timestamp["value"]) self.publish_message(message=message) end_time = int((datetime.now() + timedelta(days=8000)).timestamp() * 1e9) @@ -211,12 +209,14 @@ class TestTimeFilter(StepsStore): logger.debug(f"number of messages stored for start time {start_time} and " f"end time = {end_time} is {len(store_response.messages)}") assert len(store_response.messages) == 6, "number of messages retrieved doesn't match time filter " + @pytest.mark.skipif("go-waku" in (NODE_1 + NODE_2), reason="Test works only with nwaku") def test_time_filter_small_timestamp(self): - start_time = self.ts_pass[0]["value"] - for timestamp in self.ts_pass: + ts_pass = self.get_time_list_pass() + start_time = ts_pass[0]["value"] + for timestamp in ts_pass: message = self.create_message(timestamp=timestamp["value"]) self.publish_message(message=message) - end_time = self.ts_pass[5]["value"] + 1 + end_time = ts_pass[5]["value"] + 1 logger.debug(f"inquering stored messages with start time {start_time} after end time {end_time}") for node in self.store_nodes: store_response = self.get_messages_from_store(node, page_size=20, start_time=start_time, end_time=end_time, include_data=True) @@ -224,8 +224,10 @@ class TestTimeFilter(StepsStore): assert len(store_response.messages) == 6, "number of messages retrieved doesn't match time filter " + @pytest.mark.skipif("go-waku" in (NODE_1 + NODE_2), reason="Test works only with nwaku") def test_time_filter_negative_end_time(self): - for timestamp in self.ts_pass: + ts_pass = self.get_time_list_pass() + for timestamp in ts_pass: message = self.create_message(timestamp=timestamp["value"]) self.publish_message(message=message) end_time = -10000 @@ -236,8 +238,10 @@ class TestTimeFilter(StepsStore): assert len(store_response.messages) == 6, "number of messages retrieved doesn't match time filter " + @pytest.mark.skipif("go-waku" in (NODE_1 + NODE_2), reason="Test works only with nwaku") def test_time_filter_zero_end_time(self): - for timestamp in self.ts_pass: + ts_pass = self.get_time_list_pass() + for timestamp in ts_pass: message = self.create_message(timestamp=timestamp["value"]) self.publish_message(message=message) end_time = 0 From dbc5bfe0f96f612504ffa153b73eba7ab28b1bbb Mon Sep 17 00:00:00 2001 From: fbarbu15 Date: Wed, 30 Oct 2024 10:49:49 +0200 Subject: [PATCH 2/3] fix lp test (#82) --- src/steps/light_push.py | 7 +++++++ tests/light_push/test_publish.py | 4 +--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/steps/light_push.py b/src/steps/light_push.py index 4fd8d929e2..ddd10a05ef 100644 --- a/src/steps/light_push.py +++ b/src/steps/light_push.py @@ -13,6 +13,7 @@ from src.env_vars import ( from src.node.waku_node import WakuNode from src.steps.common import StepsCommon from src.test_data import VALID_PUBSUB_TOPICS +from tenacity import retry, stop_after_delay, wait_fixed logger = get_custom_logger(__name__) @@ -137,3 +138,9 @@ class StepsLightPush(StepsCommon): payload = {"pubsubTopic": pubsub_topic, "message": message} payload.update(kwargs) return payload + + @allure.step + @retry(stop=stop_after_delay(120), wait=wait_fixed(1), reraise=True) + def subscribe_and_light_push_with_retry(self): + self.subscribe_to_pubsub_topics_via_relay() + self.check_light_pushed_message_reaches_receiving_peer() diff --git a/tests/light_push/test_publish.py b/tests/light_push/test_publish.py index 0d3aebcd81..03b5847645 100644 --- a/tests/light_push/test_publish.py +++ b/tests/light_push/test_publish.py @@ -267,9 +267,7 @@ class TestLightPushPublish(StepsLightPush): self.check_light_pushed_message_reaches_receiving_peer() self.receiving_node1.restart() self.receiving_node1.ensure_ready() - delay(30) - self.subscribe_to_pubsub_topics_via_relay() - self.check_light_pushed_message_reaches_receiving_peer() + self.subscribe_and_light_push_with_retry() def test_light_push_and_retrieve_100_messages(self): num_messages = 100 # if increase this number make sure to also increase rest-relay-cache-capacity flag From 4d8e7e49550fd8b34d8f1ab2366fff11bb70eb0c Mon Sep 17 00:00:00 2001 From: fbarbu15 Date: Thu, 31 Oct 2024 10:11:25 +0200 Subject: [PATCH 3/3] chore: histogram metric update (#84) --- src/test_data.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/test_data.py b/src/test_data.py index 5418d1799b..a56cc45f07 100644 --- a/src/test_data.py +++ b/src/test_data.py @@ -352,6 +352,8 @@ METRICS_WITH_INITIAL_VALUE_ZERO = [ "waku_histogram_message_size_sum", "waku_histogram_message_size_count", 'waku_histogram_message_size_bucket{le="0.0"}', + 'waku_histogram_message_size_bucket{le="1.0"}', + 'waku_histogram_message_size_bucket{le="3.0"}', 'waku_histogram_message_size_bucket{le="5.0"}', 'waku_histogram_message_size_bucket{le="15.0"}', 'waku_histogram_message_size_bucket{le="50.0"}', @@ -359,7 +361,7 @@ METRICS_WITH_INITIAL_VALUE_ZERO = [ 'waku_histogram_message_size_bucket{le="100.0"}', 'waku_histogram_message_size_bucket{le="125.0"}', 'waku_histogram_message_size_bucket{le="150.0"}', - 'waku_histogram_message_size_bucket{le="300.0"}', + 'waku_histogram_message_size_bucket{le="500.0"}', 'waku_histogram_message_size_bucket{le="700.0"}', 'waku_histogram_message_size_bucket{le="1000.0"}', 'waku_histogram_message_size_bucket{le="+Inf"}',