def test_address_in_use(): with pytest.raises(PeaFailToStart): args1 = set_pea_parser().parse_args(['--port-ctrl', '55555']) args2 = set_pea_parser().parse_args(['--port-ctrl', '55555']) with BasePea(args1), BasePea(args2): pass with pytest.raises(PeaFailToStart): args1 = set_pea_parser().parse_args(['--port-ctrl', '55555', '--runtime', 'thread']) args2 = set_pea_parser().parse_args(['--port-ctrl', '55555', '--runtime', 'thread']) with BasePea(args1), BasePea(args2): pass
def test_address_in_use(self): args1 = set_pea_parser().parse_args(['--port-ctrl', '55555']) args2 = set_pea_parser().parse_args(['--port-ctrl', '55555']) with BasePea(args1), BasePea(args2): pass args1 = set_pea_parser().parse_args(['--port-ctrl', '55555', '--runtime', 'thread']) args2 = set_pea_parser().parse_args(['--port-ctrl', '55555', '--runtime', 'thread']) with BasePea(args1), BasePea(args2): pass print('everything should quit gracefully')
def test_class_yaml(self): class DummyClass: pass yaml.register_class(DummyClass) a = yaml.load('!DummyClass {}') self.assertEqual(type(a), DummyClass) with open( resource_filename( 'jina', '/'.join( ('resources', 'executors.requests.%s.yml' % 'BaseExecutor')))) as fp: b = fp.read() print(b) c = yaml.load(b) print(c) args = set_pea_parser().parse_args([]) with BasePea(args) as p: pass from jina.executors.requests import _defaults self.assertIsNotNone(_defaults)
def test_simple_zmqlet(): args = set_pea_parser().parse_args([ '--host-in', '0.0.0.0', '--host-out', '0.0.0.0', '--port-in', '12346', '--port-out', '12347', '--socket-in', 'PULL_CONNECT', '--socket-out', 'PUSH_CONNECT', '--timeout-ctrl', '-1']) args2 = set_pea_parser().parse_args([ '--host-in', '0.0.0.0', '--host-out', '0.0.0.0', '--port-in', '12347', '--port-out', '12346', '--socket-in', 'PULL_BIND', '--socket-out', 'PUSH_BIND', '--uses', '_logforward', '--timeout-ctrl', '-1' ]) logger = logging.getLogger('zmq-test') with BasePea(args2) as z1, Zmqlet(args, logger) as z: req = jina_pb2.Request() req.request_id = uuid.uuid1().hex d = req.index.docs.add() d.tags['id'] = 2 msg = add_envelope(req, 'tmp', '') z.send_message(msg)
def test_simple_zmqlet(self): args = set_pea_parser().parse_args([ '--host-in', '0.0.0.0', '--host-out', '0.0.0.0', '--port-in', '12346', '--port-out', '12347', '--socket-in', 'PULL_CONNECT', '--socket-out', 'PUSH_CONNECT', '--timeout-ctrl', '-1']) args2 = set_pea_parser().parse_args([ '--host-in', '0.0.0.0', '--host-out', '0.0.0.0', '--port-in', '12347', '--port-out', '12346', '--socket-in', 'PULL_BIND', '--socket-out', 'PUSH_BIND', '--uses', '_logforward', '--timeout-ctrl', '-1' ]) with BasePea(args2) as z1, Zmqlet(args) as z: req = jina_pb2.Request() req.request_id = 1 d = req.index.docs.add() d.id = 2 msg = add_envelope(req, 'tmp', '') z.send_message(msg)
def test_class_yaml(): class DummyClass: pass yaml.register_class(DummyClass) a = yaml.load('!DummyClass {}') assert type(a) == DummyClass with open( resource_filename( 'jina', '/'.join( ('resources', 'executors.requests.BaseExecutor.yml')))) as fp: b = fp.read() print(b) c = yaml.load(b) print(c) args = set_pea_parser().parse_args([]) with BasePea(args): pass from jina.executors.requests import _defaults assert _defaults is not None
def test_ping(): a1 = set_pea_parser().parse_args([]) a2 = set_ping_parser().parse_args(['0.0.0.0', str(a1.port_ctrl), '--print-response']) a3 = set_ping_parser().parse_args(['0.0.0.1', str(a1.port_ctrl), '--timeout', '1000']) with pytest.raises(SystemExit) as cm: with BasePea(a1): NetworkChecker(a2) assert cm.value.code == 0 # test with bad addresss with pytest.raises(SystemExit) as cm: with BasePea(a1): NetworkChecker(a3) assert cm.value.code == 1
def test_ping(self): a1 = set_pea_parser().parse_args([]) a2 = set_ping_parser().parse_args(['0.0.0.0', str(a1.port_ctrl), '--print-response']) a3 = set_ping_parser().parse_args(['0.0.0.1', str(a1.port_ctrl), '--timeout', '1000']) with self.assertRaises(SystemExit) as cm: with BasePea(a1): NetworkChecker(a2) self.assertEqual(cm.exception.code, 0) # test with bad addresss with self.assertRaises(SystemExit) as cm: with BasePea(a1): NetworkChecker(a3) self.assertEqual(cm.exception.code, 1)
def test_container_ping(docker_image_built): a4 = set_pea_parser().parse_args(['--uses', img_name]) a5 = set_ping_parser().parse_args(['0.0.0.0', str(a4.port_ctrl), '--print-response']) # test with container with pytest.raises(SystemExit) as cm: with BasePea(a4): NetworkChecker(a5) assert cm.value.code == 0
def test_container_ping(self): a4 = set_pea_parser().parse_args(['--image', img_name]) a5 = set_ping_parser().parse_args(['0.0.0.0', str(a4.port_ctrl), '--print-response']) # test with container with self.assertRaises(SystemExit) as cm: with BasePea(a4): NetworkChecker(a5) self.assertEqual(cm.exception.code, 0)
def test_pea_context(runtime): args = set_pea_parser().parse_args(['--runtime', runtime]) with BasePea(args): pass BasePea(args).start().close()