remove traceback usage, add test

This commit is contained in:
Victor Shyba 2020-09-03 13:55:31 -03:00
parent 6bbfb45de7
commit e1b55f017b
3 changed files with 16 additions and 4 deletions

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

@ -160,8 +160,6 @@ class Daemon:
'result': encoded_result 'result': encoded_result
}) })
except Exception as e: except Exception as e:
import traceback
traceback.print_exc()
log.exception("RPC error") log.exception("RPC error")
await web_socket.send_json({'id': msg.get('id', ''), 'result': "unexpected error: " + str(e)}) await web_socket.send_json({'id': msg.get('id', ''), 'result': "unexpected error: " + str(e)})
raise e raise e

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'"
)