def test_flow_api(monkeypatch, partial_flow_client): flow_model = FlowModel() flow_model.uses = f'{cur_dir}/good_flow_dummy.yml' response = partial_flow_client.post( api, json=flow_model.dict(exclude={'log_config'}), params={'port_expose': 56789}) assert response response = partial_flow_client.get(api) assert response print(response.json()) assert response.json()['arguments']['port_expose'] == 56789 def response_checker(response): assert response.docs[0].content == 'https://jina.ai' Client(port_expose=56789).post(on='/any_endpoint', inputs=Document(), on_done=response_checker) # the pod used in this flow is not a compound pod and does not support ROLLING_UPDATE response = partial_flow_client.put( api, params={ 'kind': UpdateOperation.ROLLING_UPDATE, 'dump_path': '', 'pod_name': 'dummy_executor', 'shards': 1, }, ) assert response.status_code == 400 response = partial_flow_client.delete(api) assert response
def test_flow_api(monkeypatch, partial_flow_client): flow_model = FlowModel() flow_model.uses = f'{cur_dir}/good_flow_dummy.yml' create_response = partial_flow_client.post( api, json={'flow': flow_model.dict(exclude={'log_config'})} ) get_response = partial_flow_client.get(api) endpoint_responses = Client(port=56789).post( on='/any_endpoint', inputs=Document(), return_results=True ) rolling_update_response = partial_flow_client.put( f'{api}/rolling_update', params={ 'pod_name': 'dummy_executor', 'uses_with': {}, }, ) delete_response = partial_flow_client.delete(api) assert create_response assert get_response assert get_response.json()['arguments']['port_expose'] == 56789 assert endpoint_responses[0].docs[0].content == 'https://jina.ai' assert rolling_update_response.status_code == 200 assert delete_response
def test_flowstore_add(monkeypatch, partial_flow_store): flow_model = FlowModel() flow_model.uses = f'{cur_dir}/flow.yml' args = ArgNamespace.kwargs2namespace(flow_model.dict(), set_flow_parser()) partial_store_item = partial_flow_store.add(args) assert partial_store_item assert isinstance(partial_flow_store.object, Flow) assert 'executor1' in partial_store_item.yaml_source assert partial_flow_store.object.port_expose == 12345
def test_flowstore_scale(partial_flow_store, mocker): flow_model = FlowModel() flow_model.uses = f'{cur_dir}/flow.yml' args = ArgNamespace.kwargs2namespace(flow_model.dict(), set_flow_parser()) partial_flow_store.add(args) scale_mock = mocker.Mock() partial_flow_store.object.scale = scale_mock partial_flow_store.scale(pod_name='executor1', replicas=2) scale_mock.assert_called()
def test_flowstore_rolling_update(partial_flow_store, mocker): flow_model = FlowModel() flow_model.uses = f'{cur_dir}/flow.yml' args = ArgNamespace.kwargs2namespace(flow_model.dict(), set_flow_parser()) partial_flow_store.add(args) rolling_update_mock = mocker.Mock() partial_flow_store.object.rolling_update = rolling_update_mock partial_flow_store.rolling_update(pod_name='executor1', uses_with={}) rolling_update_mock.assert_called()
async def test_flowstore_scale(partial_flow_store, mocker): flow_model = FlowModel() flow_model.uses = f'{cur_dir}/flow.yml' args = ArgNamespace.kwargs2namespace(flow_model.dict(), set_flow_parser()) partial_flow_store.add(args) future = asyncio.Future() future.set_result(PartialStoreItem()) mocker.patch('daemon.stores.partial.PartialFlowStore.scale', return_value=future) resp = await partial_flow_store.scale(deployment_name='executor1', replicas=2) assert resp
def test_flowstore_update(partial_flow_store, mocker): flow_model = FlowModel() flow_model.uses = f'{cur_dir}/flow.yml' port_expose = helper.random_port() args = ArgNamespace.kwargs2namespace(flow_model.dict(), set_flow_parser()) partial_flow_store.add(args, port_expose) update_mock = mocker.Mock() partial_flow_store.object.rolling_update = update_mock partial_flow_store.update(kind=UpdateOperation.ROLLING_UPDATE, dump_path='', pod_name='pod1', shards=1) update_mock.assert_called()
async def test_flow_store(workspace): store = FlowStore() flow_id = DaemonID('jflow') flow_model = FlowModel() flow_model.uses = f'flow.yml' await store.add( id=flow_id, workspace_id=workspace, params=flow_model, ports={}, port_expose=56789, ) assert len(store) == 1 assert flow_id in store await store.delete(flow_id) assert flow_id not in store assert not store