Minimal test for msg queue: wait for a msg at most for 4 min
This commit is contained in:
parent
3c56afc570
commit
e5187c7887
38
minode/tests/test_queue.py
Normal file
38
minode/tests/test_queue.py
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
import time
|
||||||
|
|
||||||
|
import zmq
|
||||||
|
|
||||||
|
from .test_process import TestProcessProto
|
||||||
|
|
||||||
|
|
||||||
|
class TestProcessQueue(TestProcessProto):
|
||||||
|
_process_cmd = ['minode', '--msg-queue']
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def setUpClass(cls):
|
||||||
|
super().setUpClass()
|
||||||
|
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.SUBSCRIBE, b'obj')
|
||||||
|
|
||||||
|
def test_receive_msg(self):
|
||||||
|
"""wait a couple of messages"""
|
||||||
|
timeout = 240
|
||||||
|
start = time.time()
|
||||||
|
c = 0
|
||||||
|
while time.time() - start < timeout:
|
||||||
|
if c > 1:
|
||||||
|
return
|
||||||
|
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')
|
||||||
|
|
||||||
|
if c == 0:
|
||||||
|
self.fail('No messages received in %ss' % timeout)
|
|
@ -1,2 +1,3 @@
|
||||||
coverage
|
coverage
|
||||||
psutil
|
psutil
|
||||||
|
pyzmq
|
||||||
|
|
Loading…
Reference in New Issue
Block a user