2019-06-26 22:28:13 +02:00
|
|
|
import asyncio
|
|
|
|
|
2019-07-16 11:23:44 +02:00
|
|
|
from torba.client.basenetwork import ClientSession
|
|
|
|
from torba.orchstr8 import Conductor
|
|
|
|
from torba.testcase import IntegrationTestCase
|
|
|
|
import lbry.wallet
|
2019-06-26 22:28:13 +02:00
|
|
|
|
|
|
|
|
|
|
|
class TestSessionBloat(IntegrationTestCase):
|
|
|
|
"""
|
2019-07-16 11:23:44 +02:00
|
|
|
Tests that server cleans up stale connections after session timeout and client times out too.
|
2019-06-26 22:28:13 +02:00
|
|
|
"""
|
|
|
|
|
|
|
|
LEDGER = lbry.wallet
|
|
|
|
|
|
|
|
async def test_session_bloat_from_socket_timeout(self):
|
2019-07-16 11:23:44 +02:00
|
|
|
await self.conductor.stop_spv()
|
|
|
|
self.conductor.spv_node.session_timeout = 1
|
|
|
|
await self.conductor.start_spv()
|
|
|
|
session = ClientSession(network=None, server=self.ledger.network.client.server, timeout=0.2)
|
|
|
|
await session.create_connection()
|
|
|
|
session.ping_task.cancel()
|
|
|
|
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)
|