From 36ad834d4342709671a6b9580df7033794623285 Mon Sep 17 00:00:00 2001 From: Victor Shyba Date: Thu, 11 Oct 2018 00:07:38 -0300 Subject: [PATCH] add reconnection test --- tests/integration/test_reconnect.py | 33 +++++++++++++++++++++++++++++ tox.ini | 1 + 2 files changed, 34 insertions(+) create mode 100644 tests/integration/test_reconnect.py diff --git a/tests/integration/test_reconnect.py b/tests/integration/test_reconnect.py new file mode 100644 index 000000000..bb8c9b8ac --- /dev/null +++ b/tests/integration/test_reconnect.py @@ -0,0 +1,33 @@ +import asyncio +from orchstr8.testcase import IntegrationTestCase, d2f +from torba.constants import COIN + + +class ReconnectTests(IntegrationTestCase): + + VERBOSE = False + + async def test_connection_drop_still_receives_events_after_reconnected(self): + address1 = await d2f(self.account.receiving.get_or_create_usable_address()) + self.ledger.network.client.connectionLost() + 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 + + self.assertEqual(round(await self.get_balance(self.account)/COIN, 4), 1.1337) + # 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! + self.ledger.network.client.connectionLost() + with self.assertRaisesRegex(TimeoutError, 'Connection dropped'): + await d2f(d) + # rich but offline? no way, no water, let's retry + with self.assertRaisesRegex(ConnectionError, 'connection is not available'): + await d2f(self.ledger.network.get_transaction(sendtxid)) + # * 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! + await d2f(self.ledger.network.get_transaction(sendtxid)) + diff --git a/tox.ini b/tox.ini index e17f52069..ef05764eb 100644 --- a/tox.ini +++ b/tox.ini @@ -20,5 +20,6 @@ commands = unit: coverage run -p --source={envsitepackagesdir}/torba -m twisted.trial unit integration: orchstr8 download integration: coverage run -p --source={envsitepackagesdir}/torba -m twisted.trial --reactor=asyncio integration.test_transactions + integration: coverage run -p --source={envsitepackagesdir}/torba -m twisted.trial --reactor=asyncio integration.test_reconnect # Too slow on Travis # integration: coverage run -p --source={envsitepackagesdir}/torba -m twisted.trial --reactor=asyncio integration.test_blockchain_reorganization