forked from LBRYCommunity/lbry-sdk
44 lines
1.6 KiB
Python
44 lines
1.6 KiB
Python
import asyncio
|
|
|
|
import lbry.wallet
|
|
from lbry import __version__ as sdk_version
|
|
from torba.client.basenetwork import ClientSession
|
|
from torba.testcase import IntegrationTestCase
|
|
|
|
|
|
class TestSessions(IntegrationTestCase):
|
|
"""
|
|
Tests that server cleans up stale connections after session timeout and client times out too.
|
|
"""
|
|
|
|
LEDGER = lbry.wallet
|
|
|
|
async def test_session_bloat_from_socket_timeout(self):
|
|
await self.conductor.stop_spv()
|
|
await self.ledger.stop()
|
|
self.conductor.spv_node.session_timeout = 1
|
|
await self.conductor.start_spv()
|
|
session = ClientSession(
|
|
network=None, server=(self.conductor.spv_node.hostname, self.conductor.spv_node.port), timeout=0.2
|
|
)
|
|
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)
|
|
|
|
async def test_proper_version(self):
|
|
info = await self.ledger.network.get_server_features()
|
|
self.assertEqual(sdk_version, info['server_version'])
|
|
|
|
|
|
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)
|