Skip to content

Commit

Permalink
chore: store time filter fixes (#106)
Browse files Browse the repository at this point in the history
* chore: store time filter fixes

* adjustments
  • Loading branch information
fbarbu15 authored Feb 11, 2025
1 parent b3b902a commit 914de83
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 31 deletions.
1 change: 1 addition & 0 deletions src/node/waku_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class MessageRpcResponse:
ephemeral: Optional[bool]
meta: Optional[str]
proof: Optional[str] = field(default_factory=dict)
rateLimitProof: Optional[str] = field(default_factory=dict)
rate_limit_proof: Optional[dict] = field(default_factory=dict)


Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def set_allure_env_variables():
outfile.write(f"{attribute_name}={attribute_value}\n")


@pytest.fixture(scope="class", autouse=False)
@pytest.fixture(scope="function", autouse=False)
def start_postgres_container():
pg_container = start_postgres()
yield
Expand Down
6 changes: 4 additions & 2 deletions tests/store/test_external_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,18 @@ def node_postgres_setup(self, store_setup, start_postgres_container):
self.setup_first_store_node(store="false", relay="true")
self.subscribe_to_pubsub_topics_via_relay()

@pytest.mark.dependency(name="test_on_empty_postgress_db")
@pytest.mark.timeout(60)
def test_on_empty_postgress_db(self):
message = self.create_message()
self.publish_message(message=message)
self.check_published_message_is_stored(page_size=5, ascending="true")
assert len(self.store_response.messages) >= 1

@pytest.mark.dependency(depends=["test_on_empty_postgress_db"])
def test_on_postgress_db_with_one_message(self):
self.test_on_empty_postgress_db()
self.setup_first_publishing_node(store="true", relay="true", store_message_db_url=self.postgress_url)
self.setup_first_store_node(store="false", relay="true")
self.subscribe_to_pubsub_topics_via_relay()
message = self.create_message()
self.publish_message(message=message)
self.check_published_message_is_stored(page_size=5, ascending="true")
Expand Down
50 changes: 22 additions & 28 deletions tests/store/test_time_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,21 +90,22 @@ def test_time_filter_matches_no_message(self):
assert not store_response.messages, "Message count mismatch"

def test_time_filter_start_time_equals_end_time(self):
message_hash_list = {"nwaku": [], "gowaku": []}
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["nwaku"].append(self.compute_message_hash(self.test_pubsub_topic, message, hash_type="hex"))
message_hash_list["gowaku"].append(self.compute_message_hash(self.test_pubsub_topic, message, hash_type="base64"))
for node in self.store_nodes:
try:
self.get_messages_from_store(
node,
page_size=20,
start_time=ts_pass[0]["value"],
end_time=ts_pass[0]["value"],
)
raise Exception(f"Request for stored messages with start_time==end_time is successful")
except Exception as ex:
assert "INVALID_QUERY: startTime should be before endTime" in str(ex)
store_response = self.get_messages_from_store(
node,
page_size=20,
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[node.type()][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):
Expand All @@ -116,18 +117,15 @@ def test_time_filter_start_time_after_end_time(self):
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:
try:
self.get_messages_from_store(
node,
page_size=20,
start_time=start_time,
end_time=end_time,
)
raise Exception(f"Request for stored messages with start_time==end_time is successful")
except Exception as ex:
assert "INVALID_QUERY: startTime should be before endTime" in str(ex)
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 !"

@pytest.mark.skipif("go-waku" in (NODE_1 + NODE_2), reason="Test works only with nwaku")
def test_time_filter_negative_start_time(self):
ts_pass = self.get_time_list_pass()
for timestamp in ts_pass:
Expand All @@ -140,7 +138,6 @@ def test_time_filter_negative_start_time(self):
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 "

@pytest.mark.skipif("go-waku" in (NODE_1 + NODE_2), reason="Test works only with nwaku")
def test_time_filter_zero_start_time(self):
ts_pass = self.get_time_list_pass()
for timestamp in ts_pass:
Expand Down Expand Up @@ -206,13 +203,10 @@ def test_time_filter_big_timestamp(self):
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:
try:
self.get_messages_from_store(node, page_size=20, start_time=start_time, end_time=end_time, include_data=True)
raise Exception(f"Request for stored messages with invalid end_time {end_time} is successful")
except Exception as ex:
assert "INVALID_QUERY: time range should be smaller than one day in nanos" in str(ex)
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 "

@pytest.mark.skipif("go-waku" in (NODE_1 + NODE_2), reason="Test works only with nwaku")
def test_time_filter_small_timestamp(self):
ts_pass = self.get_time_list_pass()
start_time = ts_pass[0]["value"]
Expand Down

0 comments on commit 914de83

Please sign in to comment.