lbry-sdk/tests/client_tests/integration/test_reconnect.py

41 lines
1.8 KiB
Python
Raw Normal View History

import logging
2019-02-12 22:50:43 +01:00
import asyncio
2018-10-17 19:32:45 +02:00
2018-11-04 06:55:50 +01:00
from torba.testcase import IntegrationTestCase
2018-10-11 05:07:38 +02:00
class ReconnectTests(IntegrationTestCase):
2018-11-04 06:55:50 +01:00
VERBOSITY = logging.WARN
2018-10-11 05:07:38 +02:00
async def test_connection_drop_still_receives_events_after_reconnected(self):
2018-10-15 06:45:21 +02:00
address1 = await self.account.receiving.get_or_create_usable_address()
2018-10-17 19:32:45 +02:00
self.ledger.network.client.connection_lost(Exception())
2018-10-11 05:07:38 +02:00
sendtxid = await self.blockchain.send_to_address(address1, 1.1337)
await self.on_transaction_id(sendtxid) # mempool
await self.blockchain.generate(1)
await self.on_transaction_id(sendtxid) # confirmed
2018-11-19 05:17:39 +01:00
await self.assertBalance(self.account, '1.1337')
2018-10-11 05:07:38 +02:00
# is it real? are we rich!? let me see this tx...
d = self.ledger.network.get_transaction(sendtxid)
# what's that smoke on my ethernet cable? oh no!
2018-10-17 19:32:45 +02:00
self.ledger.network.client.connection_lost(Exception())
2019-02-12 22:50:43 +01:00
with self.assertRaises(asyncio.CancelledError):
2018-10-15 06:45:21 +02:00
await d
2018-10-11 05:07:38 +02:00
# rich but offline? no way, no water, let's retry
with self.assertRaisesRegex(ConnectionError, 'connection is not available'):
2018-10-15 06:45:21 +02:00
await self.ledger.network.get_transaction(sendtxid)
2018-10-11 05:07:38 +02:00
# * goes to pick some water outside... * time passes by and another donation comes in
sendtxid = await self.blockchain.send_to_address(address1, 42)
await self.blockchain.generate(1)
# omg, the burned cable still works! torba is fire proof!
2018-10-15 06:45:21 +02:00
await self.ledger.network.get_transaction(sendtxid)
2019-02-12 22:50:43 +01:00
async def test_timeout_then_reconnect(self):
await self.ledger.stop()
conf = self.ledger.config
self.ledger.config['connect_timeout'] = 1
self.ledger.config['default_servers'] = [('10.0.0.1', 12)] + list(conf['default_servers'])
await self.ledger.start()
self.assertTrue(self.ledger.network.is_connected)