3
3
# Distributed under the MIT software license, see the accompanying
4
4
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
5
"""Test the ZMQ notification interface."""
6
+ import os
6
7
import struct
8
+ import tempfile
7
9
from time import sleep
8
10
from io import BytesIO
9
11
30
32
from test_framework .wallet import (
31
33
MiniWallet ,
32
34
)
33
- from test_framework .netutil import test_ipv6_local
35
+ from test_framework .netutil import test_ipv6_local , test_unix_socket
34
36
35
37
36
38
# Test may be skipped and not have zmq installed
@@ -119,6 +121,10 @@ def run_test(self):
119
121
self .ctx = zmq .Context ()
120
122
try :
121
123
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." )
122
128
self .test_sequence ()
123
129
self .test_mempool_sync ()
124
130
self .test_reorg ()
@@ -139,7 +145,7 @@ def setup_zmq_test(self, services, *, recv_timeout=60, sync_blocks=True, ipv6=Fa
139
145
socket .setsockopt (zmq .IPV6 , 1 )
140
146
subscribers .append (ZMQSubscriber (socket , topic .encode ()))
141
147
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 ])
143
149
144
150
for i , sub in enumerate (subscribers ):
145
151
sub .socket .connect (services [i ][1 ])
@@ -176,12 +182,19 @@ def setup_zmq_test(self, services, *, recv_timeout=60, sync_blocks=True, ipv6=Fa
176
182
177
183
return subscribers
178
184
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" )
180
187
181
188
# Invalid zmq arguments don't take down the node, see #17185.
182
189
self .restart_node (0 , ["-zmqpubrawtx=foo" , "-zmqpubhashtx=bar" ])
183
190
184
191
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
+
185
198
subs = self .setup_zmq_test ([(topic , address ) for topic in ["hashblock" , "hashtx" , "rawblock" , "rawtx" ]])
186
199
187
200
hashblock = subs [0 ]
@@ -247,6 +260,8 @@ def test_basic(self):
247
260
])
248
261
249
262
assert_equal (self .nodes [1 ].getzmqnotifications (), [])
263
+ if unix :
264
+ os .unlink (socket_path )
250
265
251
266
def test_reorg (self ):
252
267
0 commit comments