Controller tests daemon connectivity and auth first

Server base doesn't need a task group
This commit is contained in:
Neil Booth 2018-08-13 18:48:07 +09:00
parent ab2691563f
commit b087d1492b
3 changed files with 11 additions and 12 deletions

View File

@ -13,7 +13,7 @@ import sys
import time
from functools import partial
from aiorpcx import TaskGroup
from aiorpcx import spawn
from electrumx.lib.util import class_logger
@ -93,12 +93,11 @@ class ServerBase(object):
loop.set_exception_handler(self.on_exception)
shutdown_event = asyncio.Event()
async with TaskGroup() as group:
server_task = await group.spawn(self.serve(shutdown_event))
# Wait for shutdown, log on receipt of the event
await shutdown_event.wait()
self.logger.info('shutting down')
server_task.cancel()
server_task = await spawn(self.serve(shutdown_event))
# Wait for shutdown, log on receipt of the event
await shutdown_event.wait()
self.logger.info('shutting down')
server_task.cancel()
# Prevent some silly logs
await asyncio.sleep(0.01)

View File

@ -650,10 +650,7 @@ class BlockProcessor(object):
could be lost.
'''
self._caught_up_event = caught_up_event
async with TaskGroup() as group:
await group.spawn(self._first_open_dbs())
# Ensure cached_height is set
await group.spawn(self.daemon.height())
await self._first_open_dbs()
try:
async with TaskGroup() as group:
await group.spawn(self.prefetcher.main_loop(self.height))

View File

@ -112,10 +112,13 @@ class Controller(ServerBase):
session_mgr = SessionManager(env, db, bp, daemon, mempool,
notifications, shutdown_event)
# Test daemon authentication, and also ensure it has a cached
# height. Do this before entering the task group.
await daemon.height()
caught_up_event = Event()
serve_externally_event = Event()
synchronized_event = Event()
async with TaskGroup() as group:
await group.spawn(session_mgr.serve(serve_externally_event))
await group.spawn(bp.fetch_and_process_blocks(caught_up_event))