Skip to content

Commit 403e372

Browse files
committedAug 27, 2019
qa: Relax so that the subscriber is ready before publishing zmq messages
1 parent a7be1cc commit 403e372

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed
 

‎test/functional/interface_zmq.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from test_framework.messages import CTransaction, hash256
1111
from test_framework.util import assert_equal, connect_nodes
1212
from io import BytesIO
13+
from time import sleep
1314

1415
def hash256_reversed(byte_str):
1516
return hash256(byte_str)[::-1]
@@ -61,7 +62,6 @@ def test_basic(self):
6162
address = 'tcp://127.0.0.1:28332'
6263
socket = self.ctx.socket(zmq.SUB)
6364
socket.set(zmq.RCVTIMEO, 60000)
64-
socket.connect(address)
6565

6666
# Subscribe to all available topics.
6767
hashblock = ZMQSubscriber(socket, b"hashblock")
@@ -71,6 +71,9 @@ def test_basic(self):
7171

7272
self.restart_node(0, ["-zmqpub%s=%s" % (sub.topic.decode(), address) for sub in [hashblock, hashtx, rawblock, rawtx]])
7373
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)
7477

7578
num_blocks = 5
7679
self.log.info("Generate %(n)d blocks (and %(n)d coinbase txes)" % {"n": num_blocks})
@@ -128,11 +131,13 @@ def test_reorg(self):
128131
address = 'tcp://127.0.0.1:28333'
129132
socket = self.ctx.socket(zmq.SUB)
130133
socket.set(zmq.RCVTIMEO, 60000)
131-
socket.connect(address)
132134
hashblock = ZMQSubscriber(socket, b'hashblock')
133135

134136
# Should only notify the tip if a reorg occurs
135137
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)
136141

137142
# Generate 1 block in nodes[0] and receive all notifications
138143
self.nodes[0].generatetoaddress(1, ADDRESS_BCRT1_UNSPENDABLE)

0 commit comments

Comments
 (0)
Please sign in to comment.