Changeset View
Changeset View
Standalone View
Standalone View
test/functional/interface_zmq.py
Show All 37 Lines | def set_test_params(self): | ||||
self.num_nodes = 2 | self.num_nodes = 2 | ||||
def skip_test_if_missing_module(self): | def skip_test_if_missing_module(self): | ||||
self.skip_if_no_py3_zmq() | self.skip_if_no_py3_zmq() | ||||
self.skip_if_no_bitcoind_zmq() | self.skip_if_no_bitcoind_zmq() | ||||
self.skip_if_no_wallet() | self.skip_if_no_wallet() | ||||
def setup_nodes(self): | def setup_nodes(self): | ||||
# Import keys | |||||
self.add_nodes(self.num_nodes) | |||||
self.start_nodes() | |||||
super().import_deterministic_coinbase_privkeys() | |||||
self.stop_nodes() | |||||
import zmq | import zmq | ||||
# Initialize ZMQ context and socket. | # Initialize ZMQ context and socket. | ||||
# All messages are received in the same socket which means that this | # All messages are received in the same socket which means that this | ||||
# test fails if the publishing order changes. | # test fails if the publishing order changes. | ||||
# Note that the publishing order is not defined in the documentation and | # Note that the publishing order is not defined in the documentation and | ||||
# is subject to change. | # is subject to change. | ||||
address = "tcp://127.0.0.1:28332" | address = "tcp://127.0.0.1:28332" | ||||
self.zmq_context = zmq.Context() | self.zmq_context = zmq.Context() | ||||
socket = self.zmq_context.socket(zmq.SUB) | socket = self.zmq_context.socket(zmq.SUB) | ||||
socket.set(zmq.RCVTIMEO, 60000) | socket.set(zmq.RCVTIMEO, 60000) | ||||
socket.connect(address) | socket.connect(address) | ||||
# Subscribe to all available topics. | # Subscribe to all available topics. | ||||
self.hashblock = ZMQSubscriber(socket, b"hashblock") | self.hashblock = ZMQSubscriber(socket, b"hashblock") | ||||
self.hashtx = ZMQSubscriber(socket, b"hashtx") | self.hashtx = ZMQSubscriber(socket, b"hashtx") | ||||
self.rawblock = ZMQSubscriber(socket, b"rawblock") | self.rawblock = ZMQSubscriber(socket, b"rawblock") | ||||
self.rawtx = ZMQSubscriber(socket, b"rawtx") | self.rawtx = ZMQSubscriber(socket, b"rawtx") | ||||
self.nodes[0].extra_args = ["-zmqpub{}={}".format(sub.topic.decode(), address) for sub in [ | self.extra_args = [ | ||||
self.hashblock, self.hashtx, self.rawblock, self.rawtx]] | ["-zmqpub{}={}".format(sub.topic.decode(), address) for sub in [ | ||||
self.hashblock, self.hashtx, self.rawblock, self.rawtx]], | |||||
[], | |||||
] | |||||
self.add_nodes(self.num_nodes, self.extra_args) | |||||
self.start_nodes() | self.start_nodes() | ||||
def import_deterministic_coinbase_privkeys(self): | |||||
pass | |||||
def run_test(self): | def run_test(self): | ||||
try: | try: | ||||
self._zmq_test() | self._zmq_test() | ||||
finally: | finally: | ||||
# Destroy the ZMQ context. | # Destroy the ZMQ context. | ||||
self.log.debug("Destroying ZMQ context") | self.log.debug("Destroying ZMQ context") | ||||
self.zmq_context.destroy(linger=None) | self.zmq_context.destroy(linger=None) | ||||
▲ Show 20 Lines • Show All 44 Lines • Show Last 20 Lines |