Skip to content

Commit 241803d

Browse files
committed
test: Add zmq test to support multiple interfaces
1 parent a0b2e5c commit 241803d

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

test/functional/interface_zmq.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ def run_test(self):
7575
self.test_sequence()
7676
self.test_mempool_sync()
7777
self.test_reorg()
78+
self.test_multiple_interfaces()
7879
finally:
7980
# Destroy the ZMQ context.
8081
self.log.debug("Destroying ZMQ context")
@@ -506,5 +507,28 @@ def test_mempool_sync(self):
506507

507508
self.nodes[0].generatetoaddress(1, ADDRESS_BCRT1_UNSPENDABLE)
508509

510+
def test_multiple_interfaces(self):
511+
# Set up two subscribers with different addresses
512+
subscribers = []
513+
for i in range(2):
514+
address = 'tcp://127.0.0.1:%d' % (28334 + i)
515+
socket = self.ctx.socket(zmq.SUB)
516+
socket.set(zmq.RCVTIMEO, 60000)
517+
hashblock = ZMQSubscriber(socket, b"hashblock")
518+
socket.connect(address)
519+
subscribers.append({'address': address, 'hashblock': hashblock})
520+
521+
self.restart_node(0, ['-zmqpub%s=%s' % (subscriber['hashblock'].topic.decode(), subscriber['address']) for subscriber in subscribers])
522+
523+
# Relax so that the subscriber is ready before publishing zmq messages
524+
sleep(0.2)
525+
526+
# Generate 1 block in nodes[0] and receive all notifications
527+
self.nodes[0].generatetoaddress(1, ADDRESS_BCRT1_UNSPENDABLE)
528+
529+
# Should receive the same block hash on both subscribers
530+
assert_equal(self.nodes[0].getbestblockhash(), subscribers[0]['hashblock'].receive().hex())
531+
assert_equal(self.nodes[0].getbestblockhash(), subscribers[1]['hashblock'].receive().hex())
532+
509533
if __name__ == '__main__':
510534
ZMQTest().main()

0 commit comments

Comments
 (0)