2020-08-20 16:43:44 +02:00
|
|
|
import os
|
|
|
|
import time
|
|
|
|
import asyncio
|
|
|
|
import signal
|
|
|
|
from threading import Thread
|
|
|
|
from unittest import TestCase
|
|
|
|
|
|
|
|
from lbry import Daemon, FullNode
|
2020-09-03 18:55:31 +02:00
|
|
|
from lbry.cli import execute_command
|
2020-08-20 16:43:44 +02:00
|
|
|
from lbry.console import Console
|
|
|
|
from lbry.blockchain.lbrycrd import Lbrycrd
|
2020-09-03 18:55:31 +02:00
|
|
|
from lbry.testcase import CommandTestCase
|
2020-08-20 16:43:44 +02:00
|
|
|
|
|
|
|
|
|
|
|
class TestShutdown(TestCase):
|
|
|
|
|
|
|
|
def test_graceful_fail(self):
|
|
|
|
chain_loop = asyncio.new_event_loop()
|
|
|
|
asyncio.set_event_loop(chain_loop)
|
|
|
|
chain = Lbrycrd.temp_regtest()
|
|
|
|
self.addCleanup(lambda: chain_loop.run_until_complete(chain.stop()))
|
|
|
|
self.addCleanup(lambda: asyncio.set_event_loop(chain_loop))
|
|
|
|
chain_loop.run_until_complete(chain.ensure())
|
|
|
|
chain_loop.run_until_complete(chain.start())
|
|
|
|
chain_loop.run_until_complete(chain.generate(1))
|
|
|
|
chain.ledger.conf.set(workers=2)
|
|
|
|
service = FullNode(chain.ledger)
|
|
|
|
daemon = Daemon(service, Console(service))
|
|
|
|
|
|
|
|
def send_signal():
|
|
|
|
time.sleep(2)
|
|
|
|
os.kill(os.getpid(), signal.SIGTERM)
|
|
|
|
|
|
|
|
thread = Thread(target=send_signal)
|
|
|
|
thread.start()
|
|
|
|
|
|
|
|
daemon.run()
|
2020-09-03 18:55:31 +02:00
|
|
|
|
|
|
|
|
|
|
|
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'"
|
|
|
|
)
|