added : timed_cache sub-module

This commit is contained in:
Mystical
2025-03-04 20:27:09 +05:30
committed by Paul Robinson
parent 0fa8711ca7
commit e5f3e88134
12 changed files with 158 additions and 20 deletions

View File

@ -43,21 +43,16 @@ async def test_simple_two_nodes():
@pytest.mark.trio
async def test_lru_cache_two_nodes():
# two nodes with cache_size of 4
# Mock `get_msg_id` to make us easier to manipulate `msg_id` by `data`.
async def test_timed_cache_two_nodes():
# Two nodes using LastSeenCache with a TTL of 120 seconds
def get_msg_id(msg):
# Originally it is `(msg.seqno, msg.from_id)`
return (msg.data, msg.from_id)
async with PubsubFactory.create_batch_with_floodsub(
2, cache_size=4, msg_id_constructor=get_msg_id
2, seen_ttl=120, msg_id_constructor=get_msg_id
) as pubsubs_fsub:
# `node_a` send the following messages to node_b
message_indices = [1, 1, 2, 1, 3, 1, 4, 1, 5, 1]
# `node_b` should only receive the following
expected_received_indices = [1, 2, 3, 4, 5, 1]
expected_received_indices = [1, 2, 3, 4, 5]
topic = "my_topic"

View File

@ -635,8 +635,8 @@ async def test_strict_signing():
await pubsubs_fsub[0].publish(TESTING_TOPIC, TESTING_DATA)
await trio.sleep(1)
assert len(pubsubs_fsub[0].seen_messages) == 1
assert len(pubsubs_fsub[1].seen_messages) == 1
assert pubsubs_fsub[0].seen_messages.length() == 1
assert pubsubs_fsub[1].seen_messages.length() == 1
@pytest.mark.trio