From e1b55f017b3f902231c8ecead88f2bc73ed830d8 Mon Sep 17 00:00:00 2001 From: Victor Shyba Date: Thu, 3 Sep 2020 13:55:31 -0300 Subject: [PATCH] remove traceback usage, add test --- lbry/cli.py | 5 +++-- lbry/service/daemon.py | 2 -- tests/integration/service/test_daemon.py | 13 +++++++++++++ 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/lbry/cli.py b/lbry/cli.py index 4a2b3390d..fcb9e8947 100644 --- a/lbry/cli.py +++ b/lbry/cli.py @@ -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): diff --git a/lbry/service/daemon.py b/lbry/service/daemon.py index b41b81543..a3b4e5a07 100644 --- a/lbry/service/daemon.py +++ b/lbry/service/daemon.py @@ -160,8 +160,6 @@ class Daemon: 'result': encoded_result }) except Exception as e: - import traceback - traceback.print_exc() log.exception("RPC error") await web_socket.send_json({'id': msg.get('id', ''), 'result': "unexpected error: " + str(e)}) raise e diff --git a/tests/integration/service/test_daemon.py b/tests/integration/service/test_daemon.py index 480b6f84d..5b0e34693 100644 --- a/tests/integration/service/test_daemon.py +++ b/tests/integration/service/test_daemon.py @@ -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'" + )