Skip to content

Commit

Permalink
adding integ tests for new exception written to state index
Browse files Browse the repository at this point in the history
Signed-off-by: Amit Galitzky <[email protected]>
  • Loading branch information
amitgalitz committed Mar 18, 2024
1 parent fcb4d91 commit e5ab7c3
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,21 @@ protected void getAndAssertWorkflowStatus(
Map<String, Object> responseMap = entityAsMap(response);
assertEquals(stateStatus.name(), (String) responseMap.get(CommonValue.STATE_FIELD));
assertEquals(provisioningStatus.name(), (String) responseMap.get(CommonValue.PROVISIONING_PROGRESS_FIELD));
}

/**
* Helper method to invoke the Get Workflow status Rest Action and get the error field
* @param client the rest client
* @param workflowId the workflow ID to get the status
* @return the error string
* @throws Exception if the request fails
*/
protected String getAndWorkflowStatusError(RestClient client, String workflowId) throws Exception {
Response response = getWorkflowStatus(client, workflowId, true);
assertEquals(RestStatus.OK, TestHelpers.restStatus(response));

Map<String, Object> responseMap = entityAsMap(response);
return (String) responseMap.get(CommonValue.ERROR_FIELD);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,9 +401,6 @@ public void testCreateAndProvisionIngestAndSearchPipeline() throws Exception {

public void testDefaultCohereUseCase() throws Exception {

// Using a 3 step template to create a connector, register remote model and deploy model
Template template = TestHelpers.createTemplateFromFile("ingest-search-pipeline-template.json");

// Hit Create Workflow API with original template
Response response = createWorkflowWithUseCase(client(), "cohere-embedding_model_deploy");
assertEquals(RestStatus.CREATED, TestHelpers.restStatus(response));
Expand Down Expand Up @@ -440,4 +437,35 @@ public void testDefaultCohereUseCase() throws Exception {
assertEquals(3, resourcesCreated.size());
}

public void testDefaultSemanticSearchUseCaseWithFailureExpected() throws Exception {

// Hit Create Workflow API with original template
Response response = createWorkflowWithUseCase(client(), "semantic_search");
assertEquals(RestStatus.CREATED, TestHelpers.restStatus(response));

Map<String, Object> responseMap = entityAsMap(response);
String workflowId = (String) responseMap.get(WORKFLOW_ID);
getAndAssertWorkflowStatus(client(), workflowId, State.NOT_STARTED, ProvisioningProgress.NOT_STARTED);

// Ensure Ml config index is initialized as creating a connector requires this, then hit Provision API and assert status
if (!indexExistsWithAdminClient(".plugins-ml-config")) {
assertBusy(() -> assertTrue(indexExistsWithAdminClient(".plugins-ml-config")), 40, TimeUnit.SECONDS);
response = provisionWorkflow(client(), workflowId);
} else {
response = provisionWorkflow(client(), workflowId);
}

// expecting a failure since there is no neural-search plugin in cluster to provide text-embedding processor
assertEquals(RestStatus.OK, TestHelpers.restStatus(response));
getAndAssertWorkflowStatus(client(), workflowId, State.FAILED, ProvisioningProgress.FAILED);

String error = getAndWorkflowStatusError(client(), workflowId);
assertTrue(
error.contains(
"org.opensearch.flowframework.exception.WorkflowStepException during step create_ingest_pipeline, restStatus: BAD_REQUEST"
)
);

}

}

0 comments on commit e5ab7c3

Please sign in to comment.