10
10
from test_framework .messages import CTransaction , hash256
11
11
from test_framework .util import assert_equal , connect_nodes
12
12
from io import BytesIO
13
+ from time import sleep
13
14
14
15
def hash256_reversed (byte_str ):
15
16
return hash256 (byte_str )[::- 1 ]
@@ -61,7 +62,6 @@ def test_basic(self):
61
62
address = 'tcp://127.0.0.1:28332'
62
63
socket = self .ctx .socket (zmq .SUB )
63
64
socket .set (zmq .RCVTIMEO , 60000 )
64
- socket .connect (address )
65
65
66
66
# Subscribe to all available topics.
67
67
hashblock = ZMQSubscriber (socket , b"hashblock" )
@@ -71,6 +71,9 @@ def test_basic(self):
71
71
72
72
self .restart_node (0 , ["-zmqpub%s=%s" % (sub .topic .decode (), address ) for sub in [hashblock , hashtx , rawblock , rawtx ]])
73
73
connect_nodes (self .nodes [0 ], 1 )
74
+ socket .connect (address )
75
+ # Relax so that the subscriber is ready before publishing zmq messages
76
+ sleep (0.2 )
74
77
75
78
num_blocks = 5
76
79
self .log .info ("Generate %(n)d blocks (and %(n)d coinbase txes)" % {"n" : num_blocks })
@@ -128,11 +131,13 @@ def test_reorg(self):
128
131
address = 'tcp://127.0.0.1:28333'
129
132
socket = self .ctx .socket (zmq .SUB )
130
133
socket .set (zmq .RCVTIMEO , 60000 )
131
- socket .connect (address )
132
134
hashblock = ZMQSubscriber (socket , b'hashblock' )
133
135
134
136
# Should only notify the tip if a reorg occurs
135
137
self .restart_node (0 , ['-zmqpub%s=%s' % (hashblock .topic .decode (), address )])
138
+ socket .connect (address )
139
+ # Relax so that the subscriber is ready before publishing zmq messages
140
+ sleep (0.2 )
136
141
137
142
# Generate 1 block in nodes[0] and receive all notifications
138
143
self .nodes [0 ].generatetoaddress (1 , ADDRESS_BCRT1_UNSPENDABLE )
0 commit comments