Skip to content

Commit e9c9aee

Browse files
committed
Update vlsd test harness wrt reserve_unused_port, stderr_redir, network, and vlsd job control
1 parent 3dd3c48 commit e9c9aee

File tree

1 file changed

+27
-10
lines changed
  • contrib/pyln-testing/pyln/testing

1 file changed

+27
-10
lines changed

contrib/pyln-testing/pyln/testing/utils.py

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -580,13 +580,13 @@ def getnewaddress(self):
580580

581581

582582
class ValidatingLightningSignerD(TailableProc):
583-
def __init__(self, vlsd_dir, vlsd_port, node_id):
584-
TailableProc.__init__(self, vlsd_dir)
583+
def __init__(self, vlsd_dir, vlsd_port, node_id, network):
584+
TailableProc.__init__(self, vlsd_dir, verbose=True)
585585
self.executable = env("REMOTE_SIGNER_CMD", 'vlsd')
586586
self.opts = [
587587
'--log-level-console=DEBUG',
588588
'--log-level-disk=DEBUG',
589-
'--network={}'.format(TEST_NETWORK),
589+
'--network={}'.format(network),
590590
'--datadir={}'.format(vlsd_dir),
591591
'--port={}'.format(vlsd_port),
592592
'--initial-allowlist-file={}'.format(env('REMOTE_SIGNER_ALLOWLIST',
@@ -603,9 +603,9 @@ def __init__(self, vlsd_dir, vlsd_port, node_id):
603603
def cmd_line(self):
604604
return [self.executable] + self.opts
605605

606-
def start(self, stdin=None, stdout=None, stderr=None,
606+
def start(self, stdin=None, stdout_redir=True, stderr_redir=True,
607607
wait_for_initialized=True):
608-
TailableProc.start(self, stdin, stdout, stderr)
608+
TailableProc.start(self, stdin, stdout_redir, stderr_redir)
609609
# We need to always wait for initialization
610610
self.wait_for_log("vlsd [0-9]* ready on .*:{}".format(self.vlsd_port))
611611
logging.info("vlsd started")
@@ -614,8 +614,11 @@ def stop(self, timeout=10):
614614
logging.info("stopping vlsd")
615615
rc = TailableProc.stop(self, timeout)
616616
logging.info("vlsd stopped")
617+
self.logs_catchup()
617618
return rc
618619

620+
def __del__(self):
621+
self.logs_catchup()
619622

620623
class LightningD(TailableProc):
621624
def __init__(
@@ -636,6 +639,8 @@ def __init__(
636639
self.lightning_dir = lightning_dir
637640
self.use_vlsd = False
638641
self.vlsd_dir = os.path.join(lightning_dir, "vlsd")
642+
self.vlsd_port = None
643+
self.vlsd = None
639644
self.node_id = node_id
640645

641646
self.rpcproxy = bitcoindproxy
@@ -731,16 +736,28 @@ def cmd_line(self):
731736

732737
return self.cmd_prefix + [self.executable] + self.early_opts + opts
733738

739+
def __del__(self):
740+
if self.vlsd_port is not None:
741+
drop_unused_port(self.vlsd_port)
742+
734743
def start(self, stdin=None, wait_for_initialized=True, stderr_redir=False):
735744
try:
736745
if self.use_vlsd:
746+
# Kill any previous vlsd (we may have been restarted)
747+
if self.vlsd is not None:
748+
logging.info("killing prior vlsd")
749+
self.vlsd.kill()
750+
737751
# Start the remote signer first
738-
vlsd_port = reserve()
739-
self.vlsd = ValidatingLightningSignerD(self.vlsd_dir, vlsd_port, self.node_id)
740-
self.vlsd.start(stdin, stdout, stderr, wait_for_initialized)
752+
self.vlsd_port = reserve_unused_port()
753+
self.vlsd = ValidatingLightningSignerD(
754+
self.vlsd_dir, self.vlsd_port, self.node_id, self.opts['network'])
755+
self.vlsd.start(
756+
stdin, stdout_redir=True, stderr_redir=True,
757+
wait_for_initialized=wait_for_initialized)
741758

742759
# We can't do this in the constructor because we need a new port on each restart.
743-
self.env['REMOTE_HSMD_ENDPOINT'] = '127.0.0.1:{}'.format(vlsd_port)
760+
self.env['REMOTE_HSMD_ENDPOINT'] = '127.0.0.1:{}'.format(self.vlsd_port)
744761

745762
# Some of the remote hsmd proxies need a bitcoind RPC connection
746763
self.env['BITCOIND_RPC_URL'] = 'http://{}:{}@localhost:{}'.format(
@@ -749,7 +766,7 @@ def start(self, stdin=None, wait_for_initialized=True, stderr_redir=False):
749766
BITCOIND_CONFIG['rpcport'])
750767

751768
# The remote hsmd proxies need to know which network we are using
752-
self.env['VLS_NETWORK'] = TEST_NETWORK
769+
self.env['VLS_NETWORK'] = self.opts['network']
753770

754771
self.opts['bitcoin-rpcport'] = self.rpcproxy.rpcport
755772
TailableProc.start(self, stdin, stdout_redir=False, stderr_redir=stderr_redir)

0 commit comments

Comments
 (0)