def _test_mutable_pod(runtime): args = set_pod_parser().parse_args(['--runtime', runtime, '--replicas', '2']) with MutablePod(BasePod(args).peas_args): pass MutablePod(BasePod(args).peas_args).start().close()
def _test_pod_context(runtime): args = set_pod_parser().parse_args( ['--runtime', runtime, '--parallel', '2']) with BasePod(args): pass BasePod(args).start().close()
def _test_pod_context(runtime): args = set_pod_parser().parse_args([ '--runtime', runtime, '--parallel', '2', '--max-idle-time', '5', '--shutdown-idle' ]) with BasePod(args) as bp: bp.join() BasePod(args).start().close()
def test_ssh_mutable_pod(): p = set_pod_parser().parse_args( ['--host', '[email protected]', '--timeout', '5000']) p = BasePod(p) with RemoteSSHMutablePod(p.peas_args) as pp: assert pp.status.envelope.status.code == jina_pb2.StatusProto.READY assert pp.status is None
def test_peas_naming_with_parallel(): args = set_pod_parser().parse_args([ '--name', 'pod', '--parallel', '2', '--max-idle-time', '5', '--shutdown-idle' ]) with BasePod(args) as bp: assert bp.peas[0].name == 'pod-head' assert bp.peas[1].name == 'pod-tail' assert bp.peas[2].name == 'pod-1' assert bp.peas[3].name == 'pod-2'
def test_peas_naming_with_parallel(self): args = set_pod_parser().parse_args([ '--name', 'pod', '--parallel', '2', '--max-idle-time', '5', '--shutdown-idle' ]) with BasePod(args) as bp: self.assertEqual(bp.peas[0].name, 'pod-head') self.assertEqual(bp.peas[1].name, 'pod-tail') self.assertEqual(bp.peas[2].name, 'pod-1') self.assertEqual(bp.peas[3].name, 'pod-2')
def test_customized_pod(self): f_args = set_gateway_parser().parse_args(['--allow-spawn']) p_args = set_pod_parser().parse_args( ['--host', 'localhost', '--replicas', '3', '--port-grpc', str(f_args.port_grpc)]) p = BasePod(p_args) def start_gateway(): with GatewayPod(f_args): time.sleep(5) t = Process(target=start_gateway) t.daemon = True t.start() MutablePodSpawnHelper(p.peas_args).start()
def test_pod_gracefully_close_idle(): import time args = set_pod_parser().parse_args([ '--name', 'pod', '--parallel', '2', '--max-idle-time', '4', '--shutdown-idle' ]) start_time = time.time() with BasePod(args) as bp: while not bp.is_shutdown: time.sleep(1.5) end_time = time.time() elapsed_time = end_time - start_time assert elapsed_time > 4
def test_customized_pod2(self): f_args = set_gateway_parser().parse_args(['--allow-spawn']) p_args = set_pod_parser().parse_args( ['--host', 'localhost', '--parallel', '3', '--port-expose', str(f_args.port_expose)]) p = BasePod(p_args) def start_gateway(): with GatewayPod(f_args): time.sleep(5) t = Process(target=start_gateway) t.daemon = True t.start() with RemoteMutablePod(p.peas_args): pass t.join()
def test_logging_pod(monkeypatch): from fluent import asynchandler as fluentasynchandler def mock_emit(obj, record): msg = obj.format(record) ct = msg['context'] if ct not in ['JINA', 'PROFILE']: assert msg['log_id'] == 'logging_id' if msg['name'] == 'gateway': assert 'log_id' in msg monkeypatch.setattr(fluentasynchandler.FluentHandler, "emit", mock_emit) args = set_pod_parser().parse_args(['--log-id', 'logging_id']) with BasePod(args): pass
def test_pod_status(self): args = set_pod_parser().parse_args(['--parallel', '3']) with BasePod(args) as p: assert len(p.status) == p.num_peas for v in p.status: self.assertIsNotNone(v)
def test_pod_status(self): args = set_pod_parser().parse_args(['--replicas', '3']) with BasePod(args) as p: self.assertEqual(len(p.status), p.num_peas) for v in p.status: self.assertIsNotNone(v)