Add CLI unit test for keyboard interrupt

This commit is contained in:
Chris Baumler 2019-10-15 17:54:55 -05:00 committed by Lex Berezhny
parent dfc1e6a2b9
commit ba48713219
2 changed files with 12 additions and 0 deletions

View file

@ -474,6 +474,8 @@ class Daemon(metaclass=JSONRPCServerType):
self.component_startup_task.cancel()
log.info("stopped api components")
if shutdown_runner:
self.rpc_runner.app.on_shutdown.freeze()
self.streaming_runner.app.on_shutdown.freeze()
await self.rpc_runner.shutdown()
await self.streaming_runner.shutdown()
await self.rpc_runner.cleanup()

View file

@ -7,6 +7,7 @@ from io import StringIO
from unittest import TestCase
from types import SimpleNamespace
from contextlib import asynccontextmanager
from unittest.mock import patch
import docopt
from torba.testcase import AsyncioTestCase
@ -193,6 +194,15 @@ class CLITest(AsyncioTestCase):
"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):