Skip to content

Commit 791dea2

Browse files
committed
test: cover unix sockets in zmq interface
1 parent c87b0a0 commit 791dea2

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

test/functional/interface_zmq.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
# Distributed under the MIT software license, see the accompanying
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
55
"""Test the ZMQ notification interface."""
6+
import os
67
import struct
8+
import tempfile
79
from time import sleep
810
from io import BytesIO
911

@@ -30,7 +32,7 @@
3032
from test_framework.wallet import (
3133
MiniWallet,
3234
)
33-
from test_framework.netutil import test_ipv6_local
35+
from test_framework.netutil import test_ipv6_local, test_unix_socket
3436

3537

3638
# Test may be skipped and not have zmq installed
@@ -119,6 +121,10 @@ def run_test(self):
119121
self.ctx = zmq.Context()
120122
try:
121123
self.test_basic()
124+
if test_unix_socket():
125+
self.test_basic(unix=True)
126+
else:
127+
self.log.info("Skipping ipc test, because UNIX sockets are not supported.")
122128
self.test_sequence()
123129
self.test_mempool_sync()
124130
self.test_reorg()
@@ -139,7 +145,7 @@ def setup_zmq_test(self, services, *, recv_timeout=60, sync_blocks=True, ipv6=Fa
139145
socket.setsockopt(zmq.IPV6, 1)
140146
subscribers.append(ZMQSubscriber(socket, topic.encode()))
141147

142-
self.restart_node(0, [f"-zmqpub{topic}={address}" for topic, address in services])
148+
self.restart_node(0, [f"-zmqpub{topic}={address.replace('ipc://', 'unix:')}" for topic, address in services])
143149

144150
for i, sub in enumerate(subscribers):
145151
sub.socket.connect(services[i][1])
@@ -176,12 +182,19 @@ def setup_zmq_test(self, services, *, recv_timeout=60, sync_blocks=True, ipv6=Fa
176182

177183
return subscribers
178184

179-
def test_basic(self):
185+
def test_basic(self, unix = False):
186+
self.log.info(f"Running basic test with {'ipc' if unix else 'tcp'} protocol")
180187

181188
# Invalid zmq arguments don't take down the node, see #17185.
182189
self.restart_node(0, ["-zmqpubrawtx=foo", "-zmqpubhashtx=bar"])
183190

184191
address = f"tcp://127.0.0.1:{self.zmq_port_base}"
192+
193+
if unix:
194+
# Use the shortest temp path possible since paths may have as little as 92-char limit
195+
socket_path = tempfile.NamedTemporaryFile().name
196+
address = f"ipc://{socket_path}"
197+
185198
subs = self.setup_zmq_test([(topic, address) for topic in ["hashblock", "hashtx", "rawblock", "rawtx"]])
186199

187200
hashblock = subs[0]
@@ -247,6 +260,8 @@ def test_basic(self):
247260
])
248261

249262
assert_equal(self.nodes[1].getzmqnotifications(), [])
263+
if unix:
264+
os.unlink(socket_path)
250265

251266
def test_reorg(self):
252267

0 commit comments

Comments
 (0)