Skip to content

Commit 324302d

Browse files
committed
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 fcd92fe commit 324302d

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
@@ -818,7 +818,12 @@ def test_address(node_factory):
818818

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

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

876881

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

881-
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
882-
sock.connect(l1.rpc.socket_path)
896+
sock = connect_unix(l1.rpc.socket_path)
883897

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

908-
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
909-
sock.connect(l1.rpc.socket_path)
922+
sock = connect_unix(l1.rpc.socket_path)
910923

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

939-
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
940-
sock.connect(l1.rpc.socket_path)
952+
sock = connect_unix(l1.rpc.socket_path)
941953

942954
# No ID
943955
sock.sendall(b'{"jsonrpc":"2.0","method":"getinfo","params":[]}')
@@ -2023,8 +2035,7 @@ def test_check_command(node_factory):
20232035
host='x', port="abcd")
20242036

20252037
# FIXME: python wrapper doesn't let us test array params.
2026-
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
2027-
sock.connect(l1.rpc.socket_path)
2038+
sock = connect_unix(l1.rpc.socket_path)
20282039

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

0 commit comments

Comments
 (0)