Skip to content

Commit 552df49

Browse files
whitslackrustyrussell
authored andcommitted
tests: work around socket path name too long on Linux
When running the integration test suite in a deeply nested directory tree, the path name of the Unix domain socket might be longer than can fit in a struct sockaddr_un. On Linux, we can use the /proc/self/cwd trick to shorten the path name. Changelog-Fixed: Integration tests no longer fail when run in a deeply nested directory on Linux.
1 parent 5b06e65 commit 552df49

File tree

3 files changed

+27
-9
lines changed

3 files changed

+27
-9
lines changed

tests/fixtures.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ def __init__(self, *args, **kwargs):
2121
kwargs["executable"] = "lightningd/lightningd"
2222
utils.LightningNode.__init__(self, *args, **kwargs)
2323

24+
# Avoid socket path name too long on Linux
25+
if os.uname()[0] == 'Linux' and \
26+
len(str(self.lightning_dir / TEST_NETWORK / 'lightning-rpc')) >= 108:
27+
self.daemon.opts['rpc-file'] = '/proc/self/cwd/lightning-rpc'
28+
2429
# This is a recent innovation, and we don't want to nail pyln-testing to this version.
2530
self.daemon.opts['dev-crash-after'] = 3600
2631

tests/test_cln_rs.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ def test_rpc_client(node_factory):
2727
l1 = node_factory.get_node()
2828
bin_path = Path.cwd() / "target" / RUST_PROFILE / "examples" / "cln-rpc-getinfo"
2929
rpc_path = Path(l1.daemon.lightning_dir) / TEST_NETWORK / "lightning-rpc"
30+
if len(str(rpc_path)) >= 108 and os.uname()[0] == 'Linux':
31+
rpc_path = Path('/proc/self/cwd') / os.path.relpath(rpc_path)
3032
out = subprocess.check_output([bin_path, rpc_path], stderr=subprocess.STDOUT)
3133
assert(b'0266e4598d1d3c415f572a8488830b60f7e744ed9235eb0b1ba93283b315c03518' in out)
3234

tests/test_misc.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,12 @@ def test_address(node_factory):
819819

820820
# Now test UNIX domain binding
821821
l1.stop()
822-
l1.daemon.opts['bind-addr'] = os.path.join(l1.daemon.lightning_dir, TEST_NETWORK, "sock")
822+
bind_addr = os.path.join(l1.daemon.lightning_dir, TEST_NETWORK, "sock")
823+
if len(bind_addr) >= 108 and os.uname()[0] == "Linux":
824+
bind_addr = os.path.join('/proc/self/cwd',
825+
os.path.relpath(node_factory.directory, os.path.dirname(bind_addr)),
826+
os.path.relpath(bind_addr, node_factory.directory))
827+
l1.daemon.opts['bind-addr'] = bind_addr
823828
l1.start()
824829

825830
# Test dev-allow-localhost
@@ -875,12 +880,21 @@ def test_listconfigs_plugins(node_factory, bitcoind, chainparams):
875880
assert [p['active'] for p in plugins if p['name'].endswith('offers')] == [True]
876881

877882

883+
def connect_unix(socket_path: str):
884+
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
885+
try:
886+
sock.connect(socket_path)
887+
except OSError as err:
888+
if err.args[0] == 'AF_UNIX path too long' and os.uname()[0] == 'Linux':
889+
sock.connect(os.path.join('/proc/self/cwd', os.path.relpath(socket_path)))
890+
return sock
891+
892+
878893
def test_multirpc(node_factory):
879894
"""Test that we can do multiple RPC without waiting for response"""
880895
l1 = node_factory.get_node()
881896

882-
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
883-
sock.connect(l1.rpc.socket_path)
897+
sock = connect_unix(l1.rpc.socket_path)
884898

885899
commands = [
886900
b'{"id":1,"jsonrpc":"2.0","method":"listpeers","params":[]}',
@@ -906,8 +920,7 @@ def test_multiplexed_rpc(node_factory):
906920
"""Test that we can do multiple RPCs which exit in different orders"""
907921
l1 = node_factory.get_node()
908922

909-
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
910-
sock.connect(l1.rpc.socket_path)
923+
sock = connect_unix(l1.rpc.socket_path)
911924

912925
# Neighbouring ones may be in or out of order.
913926
commands = [
@@ -937,8 +950,7 @@ def test_malformed_rpc(node_factory):
937950
"""Test that we get a correct response to malformed RPC commands"""
938951
l1 = node_factory.get_node()
939952

940-
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
941-
sock.connect(l1.rpc.socket_path)
953+
sock = connect_unix(l1.rpc.socket_path)
942954

943955
# No ID
944956
sock.sendall(b'{"jsonrpc":"2.0","method":"getinfo","params":[]}')
@@ -2026,8 +2038,7 @@ def test_check_command(node_factory):
20262038
host='x', port="abcd")
20272039

20282040
# FIXME: python wrapper doesn't let us test array params.
2029-
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
2030-
sock.connect(l1.rpc.socket_path)
2041+
sock = connect_unix(l1.rpc.socket_path)
20312042

20322043
sock.sendall(b'{"id":1, "jsonrpc":"2.0","method":"check","params":["help"]}')
20332044
obj, _ = l1.rpc._readobj(sock, b'')

0 commit comments

Comments
 (0)