Skip to content

Commit c29e5ff

Browse files
devrandomksedgwic
authored andcommitted
tests: integrate lssd
1 parent d0be63f commit c29e5ff

File tree

4 files changed

+72
-8
lines changed

4 files changed

+72
-8
lines changed

contrib/pyln-testing/pyln/testing/fixtures.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from concurrent import futures
22
from pyln.testing.db import SqliteDbProvider, PostgresDbProvider
3-
from pyln.testing.utils import NodeFactory, BitcoinD, ElementsD, env, LightningNode, TEST_DEBUG
3+
from pyln.testing.utils import NodeFactory, BitcoinD, ElementsD, env, LightningNode, TEST_DEBUG, LssD
44
from pyln.client import Millisatoshi
55
from typing import Dict
66

@@ -167,6 +167,25 @@ def bitcoind(directory, teardown_checks):
167167
bitcoind.proc.wait()
168168

169169

170+
@pytest.fixture
171+
def lssd(directory, teardown_checks):
172+
lssd = LssD(directory)
173+
174+
try:
175+
lssd.start()
176+
except Exception:
177+
lssd.stop()
178+
raise
179+
180+
yield lssd
181+
182+
try:
183+
lssd.stop()
184+
except Exception:
185+
lssd.proc.kill()
186+
lssd.proc.wait()
187+
188+
170189
class TeardownErrors(object):
171190
def __init__(self):
172191
self.errors = []
@@ -449,11 +468,12 @@ def jsonschemas():
449468

450469

451470
@pytest.fixture
452-
def node_factory(request, directory, test_name, bitcoind, executor, db_provider, teardown_checks, node_cls, jsonschemas):
471+
def node_factory(request, directory, test_name, bitcoind, lssd, executor, db_provider, teardown_checks, node_cls, jsonschemas):
453472
nf = NodeFactory(
454473
request,
455474
test_name,
456475
bitcoind,
476+
lssd,
457477
executor,
458478
directory=directory,
459479
db_provider=db_provider,

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

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,45 @@ def f(*args):
384384
return f
385385

386386

387+
class LssD(TailableProc):
388+
def __init__(self, directory, rpcport=None):
389+
lss_dir = os.path.join(directory, 'lss')
390+
TailableProc.__init__(self, lss_dir, verbose=False)
391+
392+
if rpcport is None:
393+
self.reserved_rpcport = reserve_unused_port()
394+
rpcport = self.reserved_rpcport
395+
else:
396+
self.reserved_rpcport = None
397+
398+
self.rpcport = rpcport
399+
self.prefix = 'lss'
400+
401+
if not os.path.exists(lss_dir):
402+
os.makedirs(lss_dir)
403+
404+
self.cmd_line = [
405+
'lssd',
406+
'--datadir={}'.format(lss_dir),
407+
'--port={}'.format(rpcport),
408+
]
409+
410+
def __del__(self):
411+
if self.reserved_rpcport is not None:
412+
drop_unused_port(self.reserved_rpcport)
413+
414+
def start(self):
415+
self.env['RUST_LOG'] = 'debug'
416+
TailableProc.start(self)
417+
self.wait_for_log("ready on", timeout=TIMEOUT)
418+
419+
logging.info("LssD started")
420+
421+
def stop(self):
422+
logging.info("Stopping LssD")
423+
return TailableProc.stop(self)
424+
425+
387426
class BitcoinD(TailableProc):
388427

389428
def __init__(self, bitcoin_dir="/tmp/bitcoind-test", rpcport=None):
@@ -621,6 +660,7 @@ def __init__(
621660
self,
622661
lightning_dir,
623662
bitcoindproxy,
663+
lssd_port,
624664
port=9735,
625665
random_hsm=False,
626666
node_id=0,
@@ -641,6 +681,7 @@ def __init__(
641681

642682
self.rpcproxy = bitcoindproxy
643683
self.env['CLN_PLUGIN_LOG'] = "cln_plugin=trace,cln_rpc=trace,cln_grpc=trace,debug"
684+
self.lssd_port = lssd_port
644685

645686
self.opts = LIGHTNINGD_CONFIG.copy()
646687
opts = {
@@ -872,7 +913,7 @@ def call(self, method, payload=None, cmdprefix=None, filter=None):
872913

873914

874915
class LightningNode(object):
875-
def __init__(self, node_id, lightning_dir, bitcoind, executor, valgrind, may_fail=False,
916+
def __init__(self, node_id, lightning_dir, bitcoind, lssd, executor, valgrind, may_fail=False,
876917
may_reconnect=False,
877918
allow_broken_log=False,
878919
allow_warning=False,
@@ -882,6 +923,7 @@ def __init__(self, node_id, lightning_dir, bitcoind, executor, valgrind, may_fai
882923
valgrind_plugins=True,
883924
**kwargs):
884925
self.bitcoin = bitcoind
926+
self.lssd = lssd
885927
self.executor = executor
886928
self.may_fail = may_fail
887929
self.may_reconnect = may_reconnect
@@ -901,6 +943,7 @@ def __init__(self, node_id, lightning_dir, bitcoind, executor, valgrind, may_fai
901943

902944
self.daemon = LightningD(
903945
lightning_dir, bitcoindproxy=bitcoind.get_proxy(),
946+
lssd_port=lssd.rpcport,
904947
port=port, random_hsm=random_hsm, node_id=node_id,
905948
grpc_port=self.grpc_port,
906949
)
@@ -1605,7 +1648,7 @@ def flock(directory: Path):
16051648
class NodeFactory(object):
16061649
"""A factory to setup and start `lightningd` daemons.
16071650
"""
1608-
def __init__(self, request, testname, bitcoind, executor, directory,
1651+
def __init__(self, request, testname, bitcoind, lssd, executor, directory,
16091652
db_provider, node_cls, jsonschemas):
16101653
if request.node.get_closest_marker("slow_test") and SLOW_MACHINE:
16111654
self.valgrind = False
@@ -1617,6 +1660,7 @@ def __init__(self, request, testname, bitcoind, executor, directory,
16171660
self.reserved_ports = []
16181661
self.executor = executor
16191662
self.bitcoind = bitcoind
1663+
self.lssd = lssd
16201664
self.directory = directory
16211665
self.lock = threading.Lock()
16221666
self.db_provider = db_provider
@@ -1702,7 +1746,7 @@ def get_node(self, node_id=None, options=None, dbfile=None,
17021746
db = self.db_provider.get_db(os.path.join(lightning_dir, TEST_NETWORK), self.testname, node_id)
17031747
db.provider = self.db_provider
17041748
node = self.node_cls(
1705-
node_id, lightning_dir, self.bitcoind, self.executor, self.valgrind, db=db,
1749+
node_id, lightning_dir, self.bitcoind, self.lssd, self.executor, self.valgrind, db=db,
17061750
port=port, options=options, may_fail=may_fail or expect_fail,
17071751
jsonschemas=self.jsonschemas,
17081752
**kwargs

tests/fixtures.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from utils import TEST_NETWORK, VALGRIND # noqa: F401,F403
2-
from pyln.testing.fixtures import directory, test_base_dir, test_name, chainparams, node_factory, bitcoind, teardown_checks, db_provider, executor, setup_logging, jsonschemas # noqa: F401,F403
2+
from pyln.testing.fixtures import directory, test_base_dir, test_name, chainparams, node_factory, bitcoind, lssd, teardown_checks, db_provider, executor, setup_logging, jsonschemas # noqa: F401,F403
33
from pyln.testing import utils
44
from utils import COMPAT
55
from pathlib import Path

tests/test_misc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2549,13 +2549,13 @@ def test_unicode_rpc(node_factory, executor, bitcoind):
25492549

25502550

25512551
@unittest.skipIf(VALGRIND, "Testing pyln doesn't exercise anything interesting in the c code.")
2552-
def test_unix_socket_path_length(node_factory, bitcoind, directory, executor, db_provider, test_base_dir):
2552+
def test_unix_socket_path_length(node_factory, bitcoind, lssd, directory, executor, db_provider, test_base_dir):
25532553
lightning_dir = os.path.join(directory, "anode" + "far" * 30 + "away")
25542554
os.makedirs(lightning_dir)
25552555
db = db_provider.get_db(lightning_dir, "test_unix_socket_path_length", 1)
25562556
db.provider = db_provider
25572557

2558-
l1 = LightningNode(1, lightning_dir, bitcoind, executor, VALGRIND, db=db, port=reserve())
2558+
l1 = LightningNode(1, lightning_dir, bitcoind, lssd, executor, VALGRIND, db=db, port=reserve())
25592559

25602560
# `LightningNode.start()` internally calls `LightningRpc.getinfo()` which
25612561
# exercises the socket logic, and raises an issue if it fails.

0 commit comments

Comments
 (0)