forked from LBRYCommunity/lbry-sdk
Minor changes
Fix typos
This commit is contained in:
parent
7191042bb8
commit
5951186463
4 changed files with 13 additions and 14 deletions
|
@ -162,7 +162,7 @@ class Node:
|
|||
for address, udp_port in known_node_urls or []
|
||||
]))
|
||||
except socket.gaierror:
|
||||
await asyncio.sleep(30)
|
||||
await asyncio.sleep(30, loop=self.loop)
|
||||
continue
|
||||
|
||||
self.protocol.peer_manager.reset()
|
||||
|
|
|
@ -823,10 +823,7 @@ class SQLiteStorage(SQLiteMixin):
|
|||
def _save_kademlia_peers(transaction: sqlite3.Connection):
|
||||
transaction.execute('delete from peer').fetchall()
|
||||
transaction.executemany(
|
||||
'insert into peer(node_id, address, udp_port, tcp_port) values (?, ?, ?, ?)', (
|
||||
tuple(
|
||||
[(binascii.hexlify(p.node_id), p.address, p.udp_port, p.tcp_port) for p in peers]
|
||||
)
|
||||
)
|
||||
'insert into peer(node_id, address, udp_port, tcp_port) values (?, ?, ?, ?)',
|
||||
tuple([(binascii.hexlify(p.node_id), p.address, p.udp_port, p.tcp_port) for p in peers])
|
||||
).fetchall()
|
||||
return await self.db.run(_save_kademlia_peers)
|
||||
|
|
|
@ -31,7 +31,6 @@ class DHTIntegrationTest(AsyncioTestCase):
|
|||
self.addCleanup(node.stop)
|
||||
node.protocol.rpc_timeout = .5
|
||||
node.protocol.ping_queue._default_delay = .5
|
||||
node._peer_search_timeout = .5
|
||||
return node
|
||||
|
||||
async def setup_network(self, size: int, start_port=40000, seed_nodes=1, external_ip='127.0.0.1'):
|
||||
|
|
|
@ -88,14 +88,14 @@ class TestNodePingQueueDiscover(AsyncioTestCase):
|
|||
n.stop()
|
||||
|
||||
|
||||
class TestTemporarilyLosingConnetction(AsyncioTestCase):
|
||||
class TestTemporarilyLosingConnection(AsyncioTestCase):
|
||||
|
||||
async def test_losing_connection(self):
|
||||
loop = asyncio.get_event_loop()
|
||||
loop = self.loop
|
||||
loop.set_debug(False)
|
||||
|
||||
peer_addresses = [
|
||||
(f'127.0.0.1', 40000+i) for i in range(10)
|
||||
('127.0.0.1', 40000+i) for i in range(10)
|
||||
]
|
||||
node_ids = [constants.generate_id(i) for i in range(10)]
|
||||
|
||||
|
@ -112,17 +112,20 @@ class TestTemporarilyLosingConnetction(AsyncioTestCase):
|
|||
with dht_mocks.mock_network_loop(loop, dht_network):
|
||||
for i, n in enumerate(nodes):
|
||||
await n._storage.open()
|
||||
self.addCleanup(n.stop)
|
||||
n.start(peer_addresses[i][0], peer_addresses[:num_seeds])
|
||||
await asyncio.gather(*[n.joined.wait() for n in nodes])
|
||||
|
||||
node = nodes[-1]
|
||||
advance = dht_mocks.get_time_accelerator(loop, loop.time())
|
||||
await advance(1000)
|
||||
await advance(500)
|
||||
|
||||
# Join the network, assert that at least the known peers are in RT
|
||||
self.assertTrue(node.joined.is_set())
|
||||
self.assertTrue(len(node.protocol.routing_table.get_peers()) >= num_seeds)
|
||||
|
||||
# Refresh, so that the peers are persisted
|
||||
self.assertFalse(len(await node._storage.get_persisted_kademlia_peers()) > num_seeds)
|
||||
await advance(4000)
|
||||
self.assertTrue(len(await node._storage.get_persisted_kademlia_peers()) > num_seeds)
|
||||
|
||||
|
@ -133,14 +136,14 @@ class TestTemporarilyLosingConnetction(AsyncioTestCase):
|
|||
|
||||
# The peers are cleared on refresh from RT and storage
|
||||
await advance(4000)
|
||||
self.assertFalse(node.protocol.routing_table.get_peers())
|
||||
self.assertFalse(await node._storage.get_persisted_kademlia_peers())
|
||||
self.assertListEqual([], node.protocol.routing_table.get_peers())
|
||||
self.assertListEqual([], await node._storage.get_persisted_kademlia_peers())
|
||||
|
||||
# Reconnect some of the previously stored - node shouldn't connect
|
||||
for peer_address, protocol in zip(peer_addresses[num_seeds+1:-2], popped_protocols[num_seeds+1:-2]):
|
||||
dht_network[peer_address] = protocol
|
||||
await advance(1000)
|
||||
self.assertEqual(0, len(node.protocol.routing_table.get_peers()))
|
||||
self.assertListEqual([], node.protocol.routing_table.get_peers())
|
||||
|
||||
# Reconnect some of the seed nodes
|
||||
for peer_address, protocol in zip(peer_addresses[:num_seeds], popped_protocols[:num_seeds]):
|
||||
|
|
Loading…
Reference in a new issue