Skip to content

Commit

Permalink
test: add zmq runtime test (#2230)
Browse files Browse the repository at this point in the history
  • Loading branch information
bwanglzu committed Mar 25, 2021
1 parent 3d1b954 commit 1c9949c
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions tests/unit/peapods/zmq/test_zmq_addr.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,70 @@
import pytest

from jina.peapods.runtimes.zmq.base import ZMQManyRuntime
from jina.peapods.zmq import Zmqlet
from jina.parsers import set_pod_parser
from jina.types.message import Message
from jina.clients.request import request_generator
from tests import random_docs


@pytest.fixture
def zmq_args_argparse():
args = [
'--name',
'test2',
'--uses-before',
'_pass',
'--parallel',
'1',
'--host',
'0.0.0.0',
'--port-expose',
'45678',
'--timeout-ctrl',
'5000',
]
return set_pod_parser().parse_args(args)


@pytest.fixture
def zmq_args_dict(zmq_args_argparse):
return vars(zmq_args_argparse)


@pytest.fixture
def runtime(zmq_args_argparse):
return ZMQManyRuntime(args=zmq_args_argparse)


@pytest.fixture
def ctrl_messages():
return [Message(None, r, 'test', '123') for r in request_generator(random_docs(10))]


@pytest.fixture(params=['zmq_args_dict', 'zmq_args_argparse'])
def test_init(request):
runtime = ZMQManyRuntime(args=request.param)
assert runtime.host == '0.0.0.0'
assert runtime.port_expose == 45678
assert runtime.timeout_ctrl == 5000


def test_cancel(runtime):
assert runtime.cancel() is None


def test_status(runtime, ctrl_messages, mocker):
mocker.patch('jina.peapods.runtimes.zmq.base.send_ctrl_message', return_value=123)
assert runtime.status == [123]


def test_is_ready(runtime, ctrl_messages, mocker):
mocker.patch(
'jina.peapods.runtimes.zmq.base.send_ctrl_message',
return_value=ctrl_messages[0],
)
assert runtime.is_ready is False


@pytest.mark.parametrize('host', ['pi@192.0.0.1', '192.0.0.1'])
Expand Down

0 comments on commit 1c9949c

Please sign in to comment.