forked from LBRYCommunity/lbry-sdk
tests: lower timeout, add test with bad and good mixed
This commit is contained in:
parent
e299a9c159
commit
407c570f8b
2 changed files with 12 additions and 3 deletions
|
@ -124,8 +124,8 @@ class UDPTrackerClientProtocol(asyncio.DatagramProtocol):
|
||||||
class TrackerClient:
|
class TrackerClient:
|
||||||
EVENT_CONTROLLER = StreamController()
|
EVENT_CONTROLLER = StreamController()
|
||||||
|
|
||||||
def __init__(self, node_id, announce_port, servers):
|
def __init__(self, node_id, announce_port, servers, timeout=10.0):
|
||||||
self.client = UDPTrackerClientProtocol()
|
self.client = UDPTrackerClientProtocol(timeout=timeout)
|
||||||
self.transport = None
|
self.transport = None
|
||||||
self.node_id = node_id or random.getrandbits(160).to_bytes(20, "big", signed=False)
|
self.node_id = node_id or random.getrandbits(160).to_bytes(20, "big", signed=False)
|
||||||
self.announce_port = announce_port
|
self.announce_port = announce_port
|
||||||
|
|
|
@ -45,7 +45,7 @@ class UDPTrackerServerProtocol(asyncio.DatagramProtocol): # for testing. Not su
|
||||||
class UDPTrackerClientTestCase(AsyncioTestCase):
|
class UDPTrackerClientTestCase(AsyncioTestCase):
|
||||||
async def asyncSetUp(self):
|
async def asyncSetUp(self):
|
||||||
self.servers = {}
|
self.servers = {}
|
||||||
self.client = TrackerClient(b"\x00" * 48, 4444, [])
|
self.client = TrackerClient(b"\x00" * 48, 4444, [], timeout=0.1)
|
||||||
await self.client.start()
|
await self.client.start()
|
||||||
self.addCleanup(self.client.stop)
|
self.addCleanup(self.client.stop)
|
||||||
await self.add_server()
|
await self.add_server()
|
||||||
|
@ -91,3 +91,12 @@ class UDPTrackerClientTestCase(AsyncioTestCase):
|
||||||
for server in self.servers.values():
|
for server in self.servers.values():
|
||||||
self.assertEqual(1, len(server.peers))
|
self.assertEqual(1, len(server.peers))
|
||||||
self.assertEqual(1, len(server.peers[info_hash]))
|
self.assertEqual(1, len(server.peers[info_hash]))
|
||||||
|
|
||||||
|
async def test_multiple_with_bad_one(self):
|
||||||
|
await asyncio.gather(*[self.add_server() for _ in range(10)])
|
||||||
|
self.client.servers.append(("127.0.0.2", 7070))
|
||||||
|
info_hash = random.getrandbits(160).to_bytes(20, "big", signed=False)
|
||||||
|
await self.client.get_peer_list(info_hash)
|
||||||
|
for server in self.servers.values():
|
||||||
|
self.assertEqual(1, len(server.peers))
|
||||||
|
self.assertEqual(1, len(server.peers[info_hash]))
|
||||||
|
|
Loading…
Reference in a new issue