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
start:
dropdb lbry
dropdb lbry --if-exists
createdb lbry
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-dir=${HOME}/.lbrycrd --data-dir=/tmp/tmp-lbrynet

View file

@ -24,7 +24,7 @@ from .ledger import Ledger, RegTestLedger
log = logging.getLogger(__name__)
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):
client = Client(f"http://{conf.api}/ws")
await client.connect()
resp = await client.send(method, **params)
print(await resp.first)
resp = await (await client.send(method, **params)).first
print(resp)
await client.disconnect()
return resp
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.receive_messages_task = asyncio.create_task(self.receive_messages())
def disconnect(self):
self.session.close()
async def disconnect(self):
await self.session.close()
self.receive_messages_task.cancel()
async def receive_messages(self):

View file

@ -152,12 +152,17 @@ class Daemon:
else:
params = msg.get('params', {})
method = getattr(self.api, msg['method'])
result = await method(**params)
encoded_result = jsonrpc_dumps_pretty(result, service=self.service)
await web_socket.send_json({
'id': msg.get('id', ''),
'result': encoded_result
})
try:
result = await method(**params)
encoded_result = jsonrpc_dumps_pretty(result, service=self.service)
await web_socket.send_json({
'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
async def on_shutdown(app):

View file

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

View file

@ -6,8 +6,10 @@ from threading import Thread
from unittest import TestCase
from lbry import Daemon, FullNode
from lbry.cli import execute_command
from lbry.console import Console
from lbry.blockchain.lbrycrd import Lbrycrd
from lbry.testcase import CommandTestCase
class TestShutdown(TestCase):
@ -33,3 +35,14 @@ class TestShutdown(TestCase):
thread.start()
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'"
)