Skip to content

Commit 6014d6e

Browse files
committed
zmq test: dedup message reception handling in ZMQSubscriber
1 parent d202054 commit 6014d6e

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

test/functional/interface_zmq.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ def __init__(self, socket, topic):
3333

3434
self.socket.setsockopt(zmq.SUBSCRIBE, self.topic)
3535

36-
def receive(self):
36+
# Receive message from publisher and verify that topic and sequence match
37+
def _receive_from_publisher_and_check(self):
3738
topic, body, seq = self.socket.recv_multipart()
3839
# Topic should match the subscriber topic.
3940
assert_equal(topic, self.topic)
@@ -42,13 +43,11 @@ def receive(self):
4243
self.sequence += 1
4344
return body
4445

46+
def receive(self):
47+
return self._receive_from_publisher_and_check()
48+
4549
def receive_sequence(self):
46-
topic, body, seq = self.socket.recv_multipart()
47-
# Topic should match the subscriber topic.
48-
assert_equal(topic, self.topic)
49-
# Sequence should be incremental.
50-
assert_equal(struct.unpack('<I', seq)[-1], self.sequence)
51-
self.sequence += 1
50+
body = self._receive_from_publisher_and_check()
5251
hash = body[:32].hex()
5352
label = chr(body[32])
5453
mempool_sequence = None if len(body) != 32+1+8 else struct.unpack("<Q", body[32+1:])[0]

0 commit comments

Comments
 (0)