Allow launching service without connecting to daemon

This commit is contained in:
Mariano Sorgente 2020-12-01 13:08:25 +09:00 committed by Yostra
parent c056cc7004
commit ab8e36e310
3 changed files with 17 additions and 7 deletions

View File

@ -39,6 +39,7 @@ class Service:
on_connect_callback: Optional[Callable] = None,
rpc_info: Optional[Tuple[type, int]] = None,
parse_cli_args=True,
connect_to_daemon=True,
):
config = load_config(root_path, "config.yaml")
ping_interval = config.get("ping_interval")
@ -47,7 +48,7 @@ class Service:
self.daemon_port = config.get("daemon_port")
assert ping_interval is not None
assert network_id is not None
self._connect_to_daemon = connect_to_daemon
self._node_type = node_type
self._service_name = service_name
@ -111,8 +112,7 @@ class Service:
await self._server.start_server(self._on_connect_callback)
self._reconnect_tasks = [
start_reconnect_task(self._server, _, self._log, self._auth_connect_peers)
for _ in self._connect_peers
start_reconnect_task(self._server, _, self._log, self._auth_connect_peers) for _ in self._connect_peers
]
self._rpc_task = None
@ -126,6 +126,7 @@ class Service:
self.daemon_port,
rpc_port,
self.stop,
self._connect_to_daemon,
)
)
@ -181,9 +182,7 @@ class Service:
self._log.info("Waiting for service _await_closed callback")
await self._node._await_closed()
self._log.info(
f"Service {self._service_name} at port {self._advertised_port} fully closed"
)
self._log.info(f"Service {self._service_name} at port {self._advertised_port} fully closed")
async def async_run_service(*args, **kwargs):

View File

@ -134,7 +134,12 @@ class TestFullNodeProtocol:
incoming_queue = await add_dummy_connection(server_1, 12312)
async def has_mempool_tx():
return incoming_queue.qsize() > 0 and (await incoming_queue.get())[0].msg.function == "has_mempool_tx"
# print((await incoming_queue.get())[0].msg)
# return False
return (
incoming_queue.qsize() > 0
and (await incoming_queue.get())[0].msg.function == "request_mempool_transactions"
)
await time_out_assert(10, has_mempool_tx, True)

View File

@ -73,6 +73,7 @@ async def setup_full_node(
kwargs.update(
parse_cli_args=False,
connect_to_daemon=False,
)
service = Service(**kwargs)
@ -129,6 +130,7 @@ async def setup_wallet_node(
kwargs = service_kwargs_for_wallet(bt.root_path, config, consensus_constants, keychain)
kwargs.update(
parse_cli_args=False,
connect_to_daemon=False,
)
service = Service(**kwargs)
@ -151,6 +153,7 @@ async def setup_harvester(port, farmer_port, consensus_constants: ConsensusConst
advertised_port=port,
connect_peers=[PeerInfo(self_hostname, farmer_port)],
parse_cli_args=False,
connect_to_daemon=False,
)
service = Service(**kwargs)
@ -185,6 +188,7 @@ async def setup_farmer(
kwargs = service_kwargs_for_farmer(bt.root_path, config, config_pool, bt.keychain, consensus_constants)
kwargs.update(
parse_cli_args=False,
connect_to_daemon=False,
)
service = Service(**kwargs)
@ -205,6 +209,7 @@ async def setup_introducer(port):
kwargs.update(
advertised_port=port,
parse_cli_args=False,
connect_to_daemon=False,
)
service = Service(**kwargs)
@ -242,6 +247,7 @@ async def setup_timelord(port, full_node_port, sanitizer, consensus_constants: C
kwargs = service_kwargs_for_timelord(bt.root_path, config, consensus_constants.DISCRIMINANT_SIZE_BITS)
kwargs.update(
parse_cli_args=False,
connect_to_daemon=False,
)
service = Service(**kwargs)