Merge pull request #3034 from lbryio/wip_fwss

misc fixes
This commit is contained in:
Lex Berezhny 2020-09-03 23:21:15 -04:00 committed by GitHub
commit 6dfa78afa3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 34 additions and 14 deletions

View file

@ -12,9 +12,9 @@ idea:
cp -r scripts/idea/* .idea cp -r scripts/idea/* .idea
start: start:
dropdb lbry dropdb lbry --if-exists
createdb lbry createdb lbry
lbrynet start --full-node \ lbrynet start --full-node \
--db-url=postgresql:///lbry --workers=28 --console=advanced --no-spv-address-filters \ --db-url=postgresql:///lbry --workers=0 --console=advanced --no-spv-address-filters \
--lbrycrd-rpc-user=lbry --lbrycrd-rpc-pass=somethingelse \ --lbrycrd-rpc-user=lbry --lbrycrd-rpc-pass=somethingelse \
--lbrycrd-dir=${HOME}/.lbrycrd --data-dir=/tmp/tmp-lbrynet --lbrycrd-dir=${HOME}/.lbrycrd --data-dir=/tmp/tmp-lbrynet

View file

@ -24,7 +24,7 @@ from .ledger import Ledger, RegTestLedger
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
DOWNLOAD_URL = ( DOWNLOAD_URL = (
'https://github.com/lbryio/lbrycrd/releases/download/v0.17.4.5/lbrycrd-linux-1745.zip' 'https://github.com/lbryio/lbrycrd/releases/download/v0.17.4.6/lbrycrd-linux-1746.zip'
) )

View file

@ -176,9 +176,10 @@ def ensure_directory_exists(path: str):
async def execute_command(conf, method, params): async def execute_command(conf, method, params):
client = Client(f"http://{conf.api}/ws") client = Client(f"http://{conf.api}/ws")
await client.connect() await client.connect()
resp = await client.send(method, **params) resp = await (await client.send(method, **params)).first
print(await resp.first) print(resp)
await client.disconnect() await client.disconnect()
return resp
def normalize_value(x, key=None): def normalize_value(x, key=None):

View file

@ -3493,8 +3493,8 @@ class Client(API):
self.ws = await self.session.ws_connect(self.url) self.ws = await self.session.ws_connect(self.url)
self.receive_messages_task = asyncio.create_task(self.receive_messages()) self.receive_messages_task = asyncio.create_task(self.receive_messages())
def disconnect(self): async def disconnect(self):
self.session.close() await self.session.close()
self.receive_messages_task.cancel() self.receive_messages_task.cancel()
async def receive_messages(self): async def receive_messages(self):

View file

@ -152,12 +152,17 @@ class Daemon:
else: else:
params = msg.get('params', {}) params = msg.get('params', {})
method = getattr(self.api, msg['method']) method = getattr(self.api, msg['method'])
result = await method(**params) try:
encoded_result = jsonrpc_dumps_pretty(result, service=self.service) result = await method(**params)
await web_socket.send_json({ encoded_result = jsonrpc_dumps_pretty(result, service=self.service)
'id': msg.get('id', ''), await web_socket.send_json({
'result': encoded_result 'id': msg.get('id', ''),
}) 'result': encoded_result
})
except Exception as e:
log.exception("RPC error")
await web_socket.send_json({'id': msg.get('id', ''), 'result': "unexpected error: " + str(e)})
raise e
@staticmethod @staticmethod
async def on_shutdown(app): async def on_shutdown(app):

View file

@ -42,4 +42,5 @@ disable=
too-many-instance-attributes, too-many-instance-attributes,
protected-access, protected-access,
unused-argument, unused-argument,
bad-continuation bad-continuation,
raise-missing-from

View file

@ -6,8 +6,10 @@ from threading import Thread
from unittest import TestCase from unittest import TestCase
from lbry import Daemon, FullNode from lbry import Daemon, FullNode
from lbry.cli import execute_command
from lbry.console import Console from lbry.console import Console
from lbry.blockchain.lbrycrd import Lbrycrd from lbry.blockchain.lbrycrd import Lbrycrd
from lbry.testcase import CommandTestCase
class TestShutdown(TestCase): class TestShutdown(TestCase):
@ -33,3 +35,14 @@ class TestShutdown(TestCase):
thread.start() thread.start()
daemon.run() daemon.run()
class WebSocketAPITestCase(CommandTestCase):
async def test_api_failure_over_websocket_doesnt_hang(self):
self.assertEqual(
await asyncio.wait_for(
execute_command(self.daemon.conf, 'resolve', {'crazyparameters': 'not there'}),
timeout=1
),
"unexpected error: resolve() got an unexpected keyword argument 'crazyparameters'"
)