Skip to content

Commit 36a44ea

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 815ac7e commit 36a44ea

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

823823
# Now test UNIX domain binding
824824
l1.stop()
825-
l1.daemon.opts['bind-addr'] = os.path.join(l1.daemon.lightning_dir, TEST_NETWORK, "sock")
825+
bind_addr = os.path.join(l1.daemon.lightning_dir, TEST_NETWORK, "sock")
826+
if len(bind_addr) >= 108 and os.uname()[0] == "Linux":
827+
bind_addr = os.path.join('/proc/self/cwd',
828+
os.path.relpath(node_factory.directory, os.path.dirname(bind_addr)),
829+
os.path.relpath(bind_addr, node_factory.directory))
830+
l1.daemon.opts['bind-addr'] = bind_addr
826831
l1.start()
827832

828833
# Test dev-allow-localhost
@@ -878,12 +883,21 @@ def test_listconfigs_plugins(node_factory, bitcoind, chainparams):
878883
assert [p['active'] for p in plugins if p['name'].endswith('offers')] == [True]
879884

880885

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

885-
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
886-
sock.connect(l1.rpc.socket_path)
900+
sock = connect_unix(l1.rpc.socket_path)
887901

888902
commands = [
889903
b'{"id":1,"jsonrpc":"2.0","method":"listpeers","params":[]}',
@@ -909,8 +923,7 @@ def test_multiplexed_rpc(node_factory):
909923
"""Test that we can do multiple RPCs which exit in different orders"""
910924
l1 = node_factory.get_node()
911925

912-
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
913-
sock.connect(l1.rpc.socket_path)
926+
sock = connect_unix(l1.rpc.socket_path)
914927

915928
# Neighbouring ones may be in or out of order.
916929
commands = [
@@ -940,8 +953,7 @@ def test_malformed_rpc(node_factory):
940953
"""Test that we get a correct response to malformed RPC commands"""
941954
l1 = node_factory.get_node()
942955

943-
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
944-
sock.connect(l1.rpc.socket_path)
956+
sock = connect_unix(l1.rpc.socket_path)
945957

946958
# No ID
947959
sock.sendall(b'{"jsonrpc":"2.0","method":"getinfo","params":[]}')
@@ -2032,8 +2044,7 @@ def test_check_command(node_factory):
20322044
host='x', port="abcd")
20332045

20342046
# FIXME: python wrapper doesn't let us test array params.
2035-
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
2036-
sock.connect(l1.rpc.socket_path)
2047+
sock = connect_unix(l1.rpc.socket_path)
20372048

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

0 commit comments

Comments
 (0)