2019-06-26 16:28:13 -04:00
|
|
|
import asyncio
|
|
|
|
|
2019-12-31 14:52:57 -05:00
|
|
|
import lbry
|
2019-07-23 13:45:10 -03:00
|
|
|
import lbry.wallet
|
2020-01-03 02:40:37 -05:00
|
|
|
from lbry.wallet.network import ClientSession
|
2019-12-31 14:52:57 -05:00
|
|
|
from lbry.testcase import IntegrationTestCase
|
2019-06-26 16:28:13 -04:00
|
|
|
|
|
|
|
|
2019-11-08 12:52:39 -03:00
|
|
|
class TestSessions(IntegrationTestCase):
|
2019-06-26 16:28:13 -04:00
|
|
|
"""
|
2019-07-16 06:23:44 -03:00
|
|
|
Tests that server cleans up stale connections after session timeout and client times out too.
|
2019-06-26 16:28:13 -04:00
|
|
|
"""
|
|
|
|
|
|
|
|
LEDGER = lbry.wallet
|
|
|
|
|
|
|
|
async def test_session_bloat_from_socket_timeout(self):
|
2019-07-16 06:23:44 -03:00
|
|
|
await self.conductor.stop_spv()
|
2019-07-21 23:26:49 -03:00
|
|
|
await self.ledger.stop()
|
2019-07-16 06:23:44 -03:00
|
|
|
self.conductor.spv_node.session_timeout = 1
|
|
|
|
await self.conductor.start_spv()
|
2019-09-03 11:28:30 -03:00
|
|
|
session = ClientSession(
|
|
|
|
network=None, server=(self.conductor.spv_node.hostname, self.conductor.spv_node.port), timeout=0.2
|
|
|
|
)
|
2019-07-16 06:23:44 -03:00
|
|
|
await session.create_connection()
|
|
|
|
await session.send_request('server.banner', ())
|
|
|
|
self.assertEqual(len(self.conductor.spv_node.server.session_mgr.sessions), 1)
|
|
|
|
self.assertFalse(session.is_closing())
|
|
|
|
await asyncio.sleep(1.1)
|
|
|
|
with self.assertRaises(asyncio.TimeoutError):
|
|
|
|
await session.send_request('server.banner', ())
|
|
|
|
self.assertTrue(session.is_closing())
|
|
|
|
self.assertEqual(len(self.conductor.spv_node.server.session_mgr.sessions), 0)
|
2019-07-23 13:45:10 -03:00
|
|
|
|
2019-11-08 12:52:39 -03:00
|
|
|
async def test_proper_version(self):
|
|
|
|
info = await self.ledger.network.get_server_features()
|
2019-12-31 14:52:57 -05:00
|
|
|
self.assertEqual(lbry.__version__, info['server_version'])
|
2019-11-08 12:52:39 -03:00
|
|
|
|
2019-11-18 12:19:16 -03:00
|
|
|
async def test_client_errors(self):
|
|
|
|
# Goal is ensuring thsoe are raised and not trapped accidentally
|
|
|
|
with self.assertRaisesRegex(Exception, 'not a valid address'):
|
|
|
|
await self.ledger.network.get_history('of the world')
|
|
|
|
with self.assertRaisesRegex(Exception, 'rejected by network rules.*TX decode failed'):
|
|
|
|
await self.ledger.network.broadcast('13370042004200')
|
|
|
|
|
2019-07-23 13:45:10 -03:00
|
|
|
|
2019-08-14 10:26:02 -03:00
|
|
|
class TestSegwitServer(IntegrationTestCase):
|
|
|
|
LEDGER = lbry.wallet
|
|
|
|
ENABLE_SEGWIT = True
|
|
|
|
|
|
|
|
async def test_at_least_it_starts(self):
|
|
|
|
await asyncio.wait_for(self.ledger.network.get_headers(0, 1), 1.0)
|