Skip to content

Commit 0c41f98

Browse files
devrandomksedgwic
authored andcommitted
tests: integrate lssd
1 parent 4ca8de6 commit 0c41f98

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, TEST_NETWORK
3+
from pyln.testing.utils import NodeFactory, BitcoinD, ElementsD, env, LightningNode, TEST_DEBUG, TEST_NETWORK, LssD
44
from pyln.client import Millisatoshi
55
from typing import Dict
66

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

170170

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

451470

452471
@pytest.fixture
453-
def node_factory(request, directory, test_name, bitcoind, executor, db_provider, teardown_checks, node_cls, jsonschemas):
472+
def node_factory(request, directory, test_name, bitcoind, lssd, executor, db_provider, teardown_checks, node_cls, jsonschemas):
454473
nf = NodeFactory(
455474
request,
456475
test_name,
457476
bitcoind,
477+
lssd,
458478
executor,
459479
directory=directory,
460480
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 = {
@@ -871,7 +912,7 @@ def call(self, method, payload=None, cmdprefix=None, filter=None):
871912

872913

873914
class LightningNode(object):
874-
def __init__(self, node_id, lightning_dir, bitcoind, executor, valgrind, may_fail=False,
915+
def __init__(self, node_id, lightning_dir, bitcoind, lssd, executor, valgrind, may_fail=False,
875916
may_reconnect=False,
876917
allow_broken_log=False,
877918
allow_warning=False,
@@ -881,6 +922,7 @@ def __init__(self, node_id, lightning_dir, bitcoind, executor, valgrind, may_fai
881922
valgrind_plugins=True,
882923
**kwargs):
883924
self.bitcoin = bitcoind
925+
self.lssd = lssd
884926
self.executor = executor
885927
self.may_fail = may_fail
886928
self.may_reconnect = may_reconnect
@@ -900,6 +942,7 @@ def __init__(self, node_id, lightning_dir, bitcoind, executor, valgrind, may_fai
900942

901943
self.daemon = LightningD(
902944
lightning_dir, bitcoindproxy=bitcoind.get_proxy(),
945+
lssd_port=lssd.rpcport,
903946
port=port, random_hsm=random_hsm, node_id=node_id,
904947
grpc_port=self.grpc_port,
905948
)
@@ -1623,7 +1666,7 @@ def flock(directory: Path):
16231666
class NodeFactory(object):
16241667
"""A factory to setup and start `lightningd` daemons.
16251668
"""
1626-
def __init__(self, request, testname, bitcoind, executor, directory,
1669+
def __init__(self, request, testname, bitcoind, lssd, executor, directory,
16271670
db_provider, node_cls, jsonschemas):
16281671
if request.node.get_closest_marker("slow_test") and SLOW_MACHINE:
16291672
self.valgrind = False
@@ -1635,6 +1678,7 @@ def __init__(self, request, testname, bitcoind, executor, directory,
16351678
self.reserved_ports = []
16361679
self.executor = executor
16371680
self.bitcoind = bitcoind
1681+
self.lssd = lssd
16381682
self.directory = directory
16391683
self.lock = threading.Lock()
16401684
self.db_provider = db_provider
@@ -1720,7 +1764,7 @@ def get_node(self, node_id=None, options=None, dbfile=None,
17201764
db = self.db_provider.get_db(os.path.join(lightning_dir, TEST_NETWORK), self.testname, node_id)
17211765
db.provider = self.db_provider
17221766
node = self.node_cls(
1723-
node_id, lightning_dir, self.bitcoind, self.executor, self.valgrind, db=db,
1767+
node_id, lightning_dir, self.bitcoind, self.lssd, self.executor, self.valgrind, db=db,
17241768
port=port, options=options, may_fail=may_fail or expect_fail,
17251769
jsonschemas=self.jsonschemas,
17261770
**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
@@ -2568,13 +2568,13 @@ def test_unicode_rpc(node_factory, executor, bitcoind):
25682568

25692569

25702570
@unittest.skipIf(VALGRIND, "Testing pyln doesn't exercise anything interesting in the c code.")
2571-
def test_unix_socket_path_length(node_factory, bitcoind, directory, executor, db_provider, test_base_dir):
2571+
def test_unix_socket_path_length(node_factory, bitcoind, lssd, directory, executor, db_provider, test_base_dir):
25722572
lightning_dir = os.path.join(directory, "anode" + "far" * 30 + "away")
25732573
os.makedirs(lightning_dir)
25742574
db = db_provider.get_db(lightning_dir, "test_unix_socket_path_length", 1)
25752575
db.provider = db_provider
25762576

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

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

0 commit comments

Comments
 (0)