Skip to content

Commit

Permalink
add integration test for tracker discovery
Browse files Browse the repository at this point in the history
  • Loading branch information
shyba committed Mar 14, 2022
1 parent c5f926f commit 1c13d0e
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tests/integration/datanetwork/test_file_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from lbry.testcase import CommandTestCase
from lbry.extras.daemon.components import TorrentSession, BACKGROUND_DOWNLOADER_COMPONENT
from lbry.wallet import Transaction
from lbry.torrent.tracker import UDPTrackerServerProtocol


class FileCommands(CommandTestCase):
Expand Down Expand Up @@ -102,6 +103,24 @@ async def test_file_management(self):
await self.daemon.jsonrpc_get('lbry://foo')
self.assertItemCount(await self.daemon.jsonrpc_file_list(), 1)

async def test_tracker_discovery(self):
port = 50990
server = UDPTrackerServerProtocol()
transport, _ = await self.loop.create_datagram_endpoint(lambda: server, local_addr=("127.0.0.1", port))
self.addCleanup(transport.close)
self.daemon.conf.fixed_peers = []
self.daemon.conf.tracker_servers = [("127.0.0.1", port)]
tx = await self.stream_create('foo', '0.01')
sd_hash = tx['outputs'][0]['value']['source']['sd_hash']
self.assertNotIn(bytes.fromhex(sd_hash)[:20], server.peers)
server.add_peer(bytes.fromhex(sd_hash)[:20], "127.0.0.1", 5567)
self.assertEqual(1, len(server.peers[bytes.fromhex(sd_hash)[:20]]))
self.assertTrue(await self.daemon.jsonrpc_file_delete(delete_all=True))
stream = await self.daemon.jsonrpc_get('foo', save_file=True)
await self.wait_files_to_complete()
self.assertEqual(0, stream.blobs_remaining)
self.assertEqual(2, len(server.peers[bytes.fromhex(sd_hash)[:20]]))

async def test_announces(self):
# announces on publish
self.assertEqual(await self.daemon.storage.get_blobs_to_announce(), [])
Expand Down

0 comments on commit 1c13d0e

Please sign in to comment.