Skip to content

Commit

Permalink
tests: add peer directly instead of relying on torrent dht
Browse files Browse the repository at this point in the history
  • Loading branch information
shyba committed Sep 9, 2022
1 parent 84d89ce commit 3021962
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions tests/integration/datanetwork/test_file_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,17 @@ def __init__(self, *a, **kw):
super().__init__(*a, **kw)
self.skip_libtorrent = False

async def add_forever(self):
while True:
for handle in self.client_session._handles.values():
handle._handle.connect_peer(('127.0.0.1', 4040))
await asyncio.sleep(.1)

async def initialize_torrent(self, tx_to_update=None):
if not hasattr(self, 'seeder_session'):
self.seeder_session = TorrentSession(self.loop, None)
self.addCleanup(self.seeder_session.stop)
await self.seeder_session.bind(port=4040)
await self.seeder_session.bind('127.0.0.1', port=4040)
btih = await self.seeder_session.add_fake_torrent()
address = await self.account.receiving.get_or_create_usable_address()
if not tx_to_update:
Expand All @@ -40,8 +46,9 @@ async def initialize_torrent(self, tx_to_update=None):
await tx.sign([self.account])
await self.broadcast_and_confirm(tx)
self.client_session = self.daemon.file_manager.source_managers['torrent'].torrent_session
self.client_session._session.add_dht_node(('localhost', 4040))
self.client_session.wait_start = False # fixme: this is super slow on tests
task = asyncio.create_task(self.add_forever())
self.addCleanup(task.cancel)
return tx, btih

@skipIf(TorrentSession is None, "libtorrent not installed")
Expand Down

0 comments on commit 3021962

Please sign in to comment.