Skip to content

Commit e70512a

Browse files
committed
Make ordering of zmq consumption irrelevant to functional test
1 parent 37485ba commit e70512a

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

test/functional/interface_zmq.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,28 +54,31 @@ def run_test(self):
5454
self.ctx.destroy(linger=None)
5555

5656
def test_basic(self):
57-
# All messages are received in the same socket which means
58-
# that this test fails if the publishing order changes.
59-
# Note that the publishing order is not defined in the documentation and
60-
# is subject to change.
6157
import zmq
6258

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

6662
address = 'tcp://127.0.0.1:28332'
67-
socket = self.ctx.socket(zmq.SUB)
68-
socket.set(zmq.RCVTIMEO, 60000)
63+
sockets = []
64+
subs = []
65+
services = [b"hashblock", b"hashtx", b"rawblock", b"rawtx"]
66+
for service in services:
67+
sockets.append(self.ctx.socket(zmq.SUB))
68+
sockets[-1].set(zmq.RCVTIMEO, 60000)
69+
subs.append(ZMQSubscriber(sockets[-1], service))
6970

7071
# Subscribe to all available topics.
71-
hashblock = ZMQSubscriber(socket, b"hashblock")
72-
hashtx = ZMQSubscriber(socket, b"hashtx")
73-
rawblock = ZMQSubscriber(socket, b"rawblock")
74-
rawtx = ZMQSubscriber(socket, b"rawtx")
72+
hashblock = subs[0]
73+
hashtx = subs[1]
74+
rawblock = subs[2]
75+
rawtx = subs[3]
7576

7677
self.restart_node(0, ["-zmqpub%s=%s" % (sub.topic.decode(), address) for sub in [hashblock, hashtx, rawblock, rawtx]])
7778
connect_nodes(self.nodes[0], 1)
78-
socket.connect(address)
79+
for socket in sockets:
80+
socket.connect(address)
81+
7982
# Relax so that the subscriber is ready before publishing zmq messages
8083
sleep(0.2)
8184

@@ -96,15 +99,16 @@ def test_basic(self):
9699
tx.calc_sha256()
97100
assert_equal(tx.hash, txid.hex())
98101

102+
# Should receive the generated raw block.
103+
block = rawblock.receive()
104+
assert_equal(genhashes[x], hash256_reversed(block[:80]).hex())
105+
99106
# Should receive the generated block hash.
100107
hash = hashblock.receive().hex()
101108
assert_equal(genhashes[x], hash)
102109
# The block should only have the coinbase txid.
103110
assert_equal([txid.hex()], self.nodes[1].getblock(hash)["tx"])
104111

105-
# Should receive the generated raw block.
106-
block = rawblock.receive()
107-
assert_equal(genhashes[x], hash256_reversed(block[:80]).hex())
108112

109113
if self.is_wallet_compiled():
110114
self.log.info("Wait for tx from second node")

0 commit comments

Comments
 (0)