Skip to content

Commit

Permalink
Change await event logic for the test_remote_select_torrents function
Browse files Browse the repository at this point in the history
  • Loading branch information
drew2a committed Nov 15, 2022
1 parent 2bcac99 commit 745bcd6
Showing 1 changed file with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import asyncio
import random
import string
import time
Expand All @@ -7,6 +8,7 @@
from os import urandom
from unittest.mock import Mock, patch

import pytest
from ipv8.keyvault.crypto import default_eccrypto
from ipv8.test.base import TestBase
from pony.orm import db_session
Expand Down Expand Up @@ -225,6 +227,7 @@ async def test_push_entry_update(self):
Test if sending back information on updated version of a metadata entry works
"""

@pytest.mark.timeout(10)
async def test_remote_select_torrents(self):
"""
Test dropping packets that go over the response limit for a remote select.
Expand All @@ -240,17 +243,19 @@ async def test_remote_select_torrents(self):
torrent = mds0.TorrentMetadata(origin_id=chan.id_, infohash=torrent_infohash, title='title1')
torrent.sign()

callback_called = asyncio.Event()
processing_results = []

def callback(request, results): # pylint: disable=unused-argument
def callback(_, results):
processing_results.extend(results)
callback_called.set()

self.nodes[1].overlay.send_remote_select(
peer, metadata_type=[REGULAR_TORRENT], infohash=torrent_infohash, processing_callback=callback
)
await self.deliver_messages()

assert len(processing_results) == 1
await callback_called.wait()

obj = processing_results[0].md_obj
assert isinstance(obj, mds1.TorrentMetadata)
assert obj.title == 'title1'
Expand All @@ -263,10 +268,13 @@ def callback(request, results): # pylint: disable=unused-argument
torrent.sign()

processing_results = []
callback_called.clear()

self.nodes[1].overlay.send_remote_select(
peer, metadata_type=[REGULAR_TORRENT], infohash=torrent_infohash, processing_callback=callback
)
await self.deliver_messages()

await callback_called.wait()

assert len(processing_results) == 1
obj = processing_results[0].md_obj
Expand Down Expand Up @@ -597,6 +605,7 @@ async def test_multiple_parallel_request(self):
b.send_remote_select(peer_a, **kwargs2, processing_callback=callback2)

original_get_entries = MetadataStore.get_entries

# Add a delay to ensure that the first query is still being processed when the second one arrives
# (the mds.get_entries() method is a synchronous one and is called from a worker thread)

Expand Down

0 comments on commit 745bcd6

Please sign in to comment.