Merge branch 'waku_edge_tests_part2' into WAKU_edge_tests

This commit is contained in:
aya 2024-10-24 12:33:52 +03:00
commit 3a7484e730
3 changed files with 218 additions and 7 deletions

View File

@ -93,7 +93,20 @@ class REST(BaseClient):
return get_messages_response.json()
def get_store_messages(
self, peer_addr, include_data, pubsub_topic, content_topics, start_time, end_time, hashes, cursor, page_size, ascending, store_v, **kwargs
self,
peer_addr,
include_data,
pubsub_topic,
content_topics,
start_time,
end_time,
hashes,
cursor,
page_size,
ascending,
store_v,
encode_pubsubtopic=True,
**kwargs,
):
base_url = f"store/{store_v}/messages"
params = []
@ -103,7 +116,10 @@ class REST(BaseClient):
if include_data is not None:
params.append(f"includeData={include_data}")
if pubsub_topic is not None:
params.append(f"pubsubTopic={quote(pubsub_topic, safe='')}")
if encode_pubsubtopic:
params.append(f"pubsubTopic={quote(pubsub_topic, safe='')}")
else:
params.append(f"pubsubTopic={pubsub_topic}")
if content_topics is not None:
params.append(f"contentTopics={quote(content_topics, safe='')}")
if start_time is not None:

View File

@ -1,3 +1,5 @@
import time
import pytest
from datetime import timedelta, datetime
from src.libs.custom_logger import get_custom_logger
@ -112,3 +114,134 @@ class TestTimeFilter(StepsStore):
)
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_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:
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}")
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,
)
logger.debug(f"response for wrong time message is {store_response.response}")
assert len(store_response.messages) == 0, "got messages with start time after end time !"
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:
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 "
def test_time_filter_big_timestamp(self):
start_time = self.ts_pass[0]["value"]
for timestamp in self.ts_pass:
message = self.create_message(timestamp=timestamp["value"])
self.publish_message(message=message)
end_time = int((datetime.now() + timedelta(days=8000)).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) == 6, "number of messages retrieved doesn't match time filter "
def test_time_filter_small_timestamp(self):
start_time = self.ts_pass[0]["value"]
for timestamp in self.ts_pass:
message = self.create_message(timestamp=timestamp["value"])
self.publish_message(message=message)
end_time = self.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)
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 "
def test_time_filter_negative_end_time(self):
for timestamp in self.ts_pass:
message = self.create_message(timestamp=timestamp["value"])
self.publish_message(message=message)
end_time = -10000
logger.debug(f"inquering stored messages with end time {end_time}")
for node in self.store_nodes:
store_response = self.get_messages_from_store(node, page_size=20, end_time=end_time, include_data=True)
logger.debug(f"number of messages stored for " 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 "
def test_time_filter_zero_end_time(self):
for timestamp in self.ts_pass:
message = self.create_message(timestamp=timestamp["value"])
self.publish_message(message=message)
end_time = 0
logger.debug(f"inquering stored messages with end time {end_time}")
for node in self.store_nodes:
store_response = self.get_messages_from_store(node, page_size=20, end_time=end_time, include_data=True)
logger.debug(f"number of messages stored for " 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 "
def test_time_filter_negative_start_time(self):
for timestamp in self.ts_pass:
message = self.create_message(timestamp=timestamp["value"])
self.publish_message(message=message)
start_time = -10000
logger.debug(f"inquering stored messages with start time {start_time}")
for node in self.store_nodes:
store_response = self.get_messages_from_store(node, page_size=20, start_time=start_time, include_data=True)
logger.debug(f"number of messages stored for " f"start time = {start_time} is {len(store_response.messages)}")
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:
message = self.create_message(timestamp=timestamp["value"])
self.publish_message(message=message)
start_time = 0
logger.debug(f"inquering stored messages with start time {start_time}")
for node in self.store_nodes:
store_response = self.get_messages_from_store(node, page_size=20, start_time=start_time, include_data=True)
logger.debug(f"number of messages stored for " f"start time = {start_time} is {len(store_response.messages)}")
assert len(store_response.messages) == 6, "number of messages retrieved doesn't match time filter "
def test_time_filter_zero_start_end_time(self):
for timestamp in self.ts_pass:
message = self.create_message(timestamp=timestamp["value"])
self.publish_message(message=message)
start_time = 0
end_time = 0
logger.debug(f"inquering stored messages with start time {start_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 " f"start time = {start_time} is {len(store_response.messages)}")
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:
message = self.create_message(timestamp=timestamp["value"])
self.publish_message(message=message)
start_time = "abc"
logger.debug(f"inquering stored messages with start time {start_time}")
try:
for node in self.store_nodes:
store_response = self.get_messages_from_store(node, page_size=20, start_time=start_time, include_data=True)
raise Exception(f" request for stored messages with invalid start time {start_time} is successful")
except Exception as e:
logger.debug(f"invalid start_time cause error {e}")
assert e.args[0].find("Bad Request for url"), "url with wrong start_time is accepted"

View File

@ -3,6 +3,7 @@ from src.env_vars import NODE_2
from src.steps.store import StepsStore
from src.test_data import CONTENT_TOPICS_DIFFERENT_SHARDS
from src.libs.custom_logger import get_custom_logger
from src.test_data import PUBSUB_TOPICS_STORE
logger = get_custom_logger(__name__)
@ -84,22 +85,26 @@ class TestTopics(StepsStore):
assert len(store_response["messages"]) == len(CONTENT_TOPICS_DIFFERENT_SHARDS), "Message count mismatch"
def test_store_with_not_valid_content_topic(self):
empty_content_topic = ""
empty_content_topic = "##"
logger.debug(f"trying to find stored messages with wrong content_topic ={empty_content_topic}")
for node in self.store_nodes:
store_response = node.get_store_messages(page_size=20, include_data="true", ascending="true", content_topics=empty_content_topic)
assert len(store_response["messages"]) == len(CONTENT_TOPICS_DIFFERENT_SHARDS), "Message count mismatch"
assert len(store_response["messages"]) == 0, "Messages shouldn't ne retrieved with invalid content_topic"
# test with space string content topic
space_content_topic = " "
try:
store_response = self.store_nodes[0].get_store_messages(
page_size=20, include_data="true", ascending="true", content_topics=space_content_topic
)
logger.debug(f" response for empty content_topic {store_response}")
logger.debug(f" response for invalid content_topic {store_response}")
assert store_response["messages"] == [], "message stored with wrong topic "
except Exception as e:
raise Exception("couldn't get stored message")
raise Exception("couldn't get stored message with invalid content_topic")
def test_store_with_wrong_url_content_topic(self):
# test with wrong url
wrong_content_topic = "myapp/1/latest/proto"
logger.debug(f"trying to find stored messages with wrong content_topic ={wrong_content_topic}")
try:
store_response = self.store_nodes[0].get_store_messages(
page_size=20, include_data="true", ascending="true", content_topics=wrong_content_topic
@ -107,4 +112,61 @@ class TestTopics(StepsStore):
logger.debug(f" response for wrong url content topic is {store_response}")
assert store_response["messages"] == [], "message stored with wrong topic "
except Exception as e:
raise Exception("couldn't get stored message")
raise Exception(f"couldn't get stored message with wrong url {wrong_content_topic}")
def test_store_with_empty_pubsub_topics(self):
# empty pubsub topic
empty_topic = ""
index = iter(self.store_nodes)
logger.debug(f"Trying to get stored msg with empty pubsub topic")
store_response = self.store_nodes[0].get_store_messages(pubsub_topic=empty_topic, include_data="true", page_size=20, ascending="true")
logger.debug(f"getting the following response when sending empty pubsub_topic {store_response}")
for msg in store_response["messages"]:
assert msg["pubsubTopic"] == self.test_pubsub_topic, "wrong pubsub topic"
logger.debug(f"messages successfully queried with empty pubsub topic ")
def test_store_with_wrong_url_pubsub_topic(self):
# wrong url pubsub topic
wrong_url_topic = PUBSUB_TOPICS_STORE[0][1:]
logger.debug(f"Trying to get stored msg with wrong url topic {wrong_url_topic}")
try:
self.publish_message(pubsub_topic=PUBSUB_TOPICS_STORE[0])
self.check_published_message_is_stored(pubsub_topic=wrong_url_topic)
raise Exception("getting stored message with wrong url pubsub topic")
except Exception as e:
logger.error(f"Topic {wrong_url_topic} is wrong ''n: {str(e)}")
assert e.args[0].find("messages': []") != -1, "Message shall not be stored for wrong topic"
def test_store_with_long_string_pubsub_topic(self):
# long topic string
long_url_topic = PUBSUB_TOPICS_STORE[0][:-1]
million = 1000000
for i in range(million):
long_url_topic += str(i)
logger.debug(f"Trying to get stored msg with url topic size million ")
self.publish_message(pubsub_topic=PUBSUB_TOPICS_STORE[0])
try:
self.check_published_message_is_stored(pubsub_topic=long_url_topic)
raise Exception("request stored message with very long topic string shouldn't be accepted")
except Exception as e:
logger.error(f"store request with very long pubsub topic wasn't accepted ")
assert e.args[0].find("Client Error: Request Header Fields Too Large for url") != -1, "error isn't for large url"
def test_store_with_wrong_encoding_pubsubtopic(self):
wrong_encoidng_topic = "%23waku%2F2%2Frs%2F3%2F0"
empty_response = []
logger.debug(f"trying get message with wrong encoded pubsub topic {wrong_encoidng_topic}")
store_response = self.store_nodes[0].get_store_messages(
pubsub_topic=wrong_encoidng_topic, encode_pubsubtopic=False, include_data="true", page_size=20, ascending="true"
)
logger.debug(f"response for getting message with wrong encoded pubsub topic {store_response}")
assert store_response["messages"] == empty_response, "Error !! message retrieved with wrong encoding pubsub_topic"
def test_store_without_encoding_pubsubtopic(self):
topic = PUBSUB_TOPICS_STORE[0]
logger.debug(f"trying get message with wrong encoded pubsub topic {topic}")
store_response = self.store_nodes[0].get_store_messages(
pubsub_topic=topic, encode_pubsubtopic=False, include_data="true", page_size=20, ascending="true"
)
logger.debug(f"response for getting message without encoding pubsub topic {store_response}")
assert store_response["messages"][0]["pubsubTopic"] == PUBSUB_TOPICS_STORE[0], "topics Don't match !!"