forked from LBRYCommunity/lbry-sdk
Add CLI unit test for keyboard interrupt
This commit is contained in:
parent
dfc1e6a2b9
commit
ba48713219
2 changed files with 12 additions and 0 deletions
|
@ -474,6 +474,8 @@ class Daemon(metaclass=JSONRPCServerType):
|
||||||
self.component_startup_task.cancel()
|
self.component_startup_task.cancel()
|
||||||
log.info("stopped api components")
|
log.info("stopped api components")
|
||||||
if shutdown_runner:
|
if shutdown_runner:
|
||||||
|
self.rpc_runner.app.on_shutdown.freeze()
|
||||||
|
self.streaming_runner.app.on_shutdown.freeze()
|
||||||
await self.rpc_runner.shutdown()
|
await self.rpc_runner.shutdown()
|
||||||
await self.streaming_runner.shutdown()
|
await self.streaming_runner.shutdown()
|
||||||
await self.rpc_runner.cleanup()
|
await self.rpc_runner.cleanup()
|
||||||
|
|
|
@ -7,6 +7,7 @@ from io import StringIO
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
from types import SimpleNamespace
|
from types import SimpleNamespace
|
||||||
from contextlib import asynccontextmanager
|
from contextlib import asynccontextmanager
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
import docopt
|
import docopt
|
||||||
from torba.testcase import AsyncioTestCase
|
from torba.testcase import AsyncioTestCase
|
||||||
|
@ -193,6 +194,15 @@ class CLITest(AsyncioTestCase):
|
||||||
"Could not connect to daemon. Are you sure it's running?"
|
"Could not connect to daemon. Are you sure it's running?"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@patch.object(Daemon, 'start', spec=Daemon, wraps=Daemon.start)
|
||||||
|
def test_keyboard_interrupt_handling(self, mock_daemon_start):
|
||||||
|
def side_effect():
|
||||||
|
raise KeyboardInterrupt
|
||||||
|
|
||||||
|
mock_daemon_start.side_effect = side_effect
|
||||||
|
self.shell(["start"])
|
||||||
|
mock_daemon_start.assert_called_once()
|
||||||
|
|
||||||
|
|
||||||
class DaemonDocsTests(TestCase):
|
class DaemonDocsTests(TestCase):
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue