From 504f12e5d097ea80d2a74bf58238ba1e6a397f27 Mon Sep 17 00:00:00 2001 From: Lee Miller Date: Wed, 9 Aug 2023 03:37:47 +0300 Subject: [PATCH] Fix and improve test_queue: - decrease timeout, remove unneeded sleep; - make and check objects from the data received in message queue; - add docstrings. --- minode/tests/test_queue.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/minode/tests/test_queue.py b/minode/tests/test_queue.py index 95e20ca..de3560a 100644 --- a/minode/tests/test_queue.py +++ b/minode/tests/test_queue.py @@ -1,11 +1,15 @@ +"""Test interprocess queues""" import time import zmq +from minode import structure, message + from .test_process import TestProcessProto class TestProcessQueue(TestProcessProto): + """A test case starting the process with queues""" _process_cmd = ['minode', '--msg-queue'] @classmethod @@ -14,7 +18,7 @@ class TestProcessQueue(TestProcessProto): context = zmq.Context() cls.socket = context.socket(zmq.SUB) cls.socket.connect('tcp://localhost:5556') - cls.socket.setsockopt(zmq.RCVTIMEO, 120000) + cls.socket.setsockopt(zmq.RCVTIMEO, 5000) cls.socket.setsockopt(zmq.SUBSCRIBE, b'obj') def test_receive_msg(self): @@ -28,11 +32,15 @@ class TestProcessQueue(TestProcessProto): try: tag, data = self.socket.recv().split(b'\x00', 1) except zmq.error.Again: - time.sleep(2) continue - else: - c += 1 - self.assertEqual(tag, b'obj') + + c += 1 + self.assertEqual(tag, b'obj') + obj_type, data = data.split(b'\x00', 1) + obj = structure.Object.from_message( + message.Message(b'object', data)) + self.assertEqual(int(obj_type), obj.object_type) + self.assertTrue(obj.is_valid()) if c == 0: self.fail('No messages received in %ss' % timeout)