mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 23:24:27 +01:00
pytest: Ensure lightningd instances have the correct numeric ids
For performance reasons we start the lightningd instances in parallel. However, if we only assign the numeric ids (used for log-prefixes and home directories) when we are already running in parallel, we are not guaranteed to get the numeric ids matching the return value of `get_nodes` or `line_graph`. With this patch we now select numeric ids before parallelizing the start. Signed-off-by: Christian Decker <@cdecker>
This commit is contained in:
committed by
Rusty Russell
parent
b5903a10b2
commit
bc5dbb6a80
@@ -733,6 +733,14 @@ class NodeFactory(object):
|
|||||||
with self.lock:
|
with self.lock:
|
||||||
return reserve()
|
return reserve()
|
||||||
|
|
||||||
|
def get_node_id(self):
|
||||||
|
"""Generate a unique numeric ID for a lightning node
|
||||||
|
"""
|
||||||
|
with self.lock:
|
||||||
|
node_id = self.next_id
|
||||||
|
self.next_id += 1
|
||||||
|
return node_id
|
||||||
|
|
||||||
def get_nodes(self, num_nodes, opts=None):
|
def get_nodes(self, num_nodes, opts=None):
|
||||||
"""Start a number of nodes in parallel, each with its own options
|
"""Start a number of nodes in parallel, each with its own options
|
||||||
"""
|
"""
|
||||||
@@ -748,17 +756,20 @@ class NodeFactory(object):
|
|||||||
jobs = []
|
jobs = []
|
||||||
for i in range(num_nodes):
|
for i in range(num_nodes):
|
||||||
node_opts, cli_opts = self.split_options(opts[i])
|
node_opts, cli_opts = self.split_options(opts[i])
|
||||||
jobs.append(self.executor.submit(self.get_node, options=cli_opts, **node_opts))
|
jobs.append(self.executor.submit(
|
||||||
|
self.get_node, options=cli_opts,
|
||||||
|
node_id=self.get_node_id(), **node_opts
|
||||||
|
))
|
||||||
|
|
||||||
return [j.result() for j in jobs]
|
return [j.result() for j in jobs]
|
||||||
|
|
||||||
def get_node(self, disconnect=None, options=None, may_fail=False,
|
def get_node(self, disconnect=None, options=None, may_fail=False,
|
||||||
may_reconnect=False, random_hsm=False,
|
may_reconnect=False, random_hsm=False,
|
||||||
feerates=(15000, 7500, 3750), start=True, log_all_io=False,
|
feerates=(15000, 7500, 3750), start=True, log_all_io=False,
|
||||||
dbfile=None):
|
dbfile=None, node_id=None):
|
||||||
with self.lock:
|
if not node_id:
|
||||||
node_id = self.next_id
|
node_id = self.get_node_id()
|
||||||
self.next_id += 1
|
|
||||||
port = self.get_next_port()
|
port = self.get_next_port()
|
||||||
|
|
||||||
lightning_dir = os.path.join(
|
lightning_dir = os.path.join(
|
||||||
|
|||||||
Reference in New Issue
Block a user