mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2025-12-31 20:36:24 +00:00
added : timed_cache sub-module
This commit is contained in:
@ -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"
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
Reference in New Issue
Block a user