Skip to content

Commit

Permalink
Handle exceptions gracefully when delete non-existent resources durin…
Browse files Browse the repository at this point in the history
…g integ test resource clean up

Signed-off-by: Weijia Zhao <[email protected]>
  • Loading branch information
weijia-aws committed Jan 30, 2025
1 parent 558da1f commit 3ab98bf
Showing 1 changed file with 26 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/
package org.opensearch.neuralsearch;

import org.opensearch.client.ResponseException;
import org.opensearch.ml.common.model.MLModelState;
import static org.opensearch.neuralsearch.common.VectorUtil.vectorAsListToArray;

Expand Down Expand Up @@ -1504,23 +1505,32 @@ protected void wipeOfTestResources(
final String modelId,
final String searchPipeline
) throws IOException {
if (ingestPipeline != null) {
deletePipeline(ingestPipeline);
}
if (searchPipeline != null) {
deleteSearchPipeline(searchPipeline);
}
if (modelId != null) {
try {
deleteModel(modelId);
} catch (AssertionError e) {
// sometimes we have flaky test that the model state doesn't change after call undeploy api
// for this case we can call undeploy api one more time
deleteModel(modelId);
try {
if (ingestPipeline != null) {
deletePipeline(ingestPipeline);
}
if (searchPipeline != null) {
deleteSearchPipeline(searchPipeline);
}
if (modelId != null) {
try {
deleteModel(modelId);
} catch (AssertionError e) {
// sometimes we have flaky test that the model state doesn't change after call undeploy api
// for this case we can call undeploy api one more time
deleteModel(modelId);
}
}
if (indexName != null) {
deleteIndex(indexName);
}
} catch (ResponseException e) {
// It's possible that test fails during resources (index, model, pipeline, etc.) creation, when clean up
// these resources after test run, the delete methods will throw ResponseException with 404 Not Found code
// In this case, we just need to ignore this exception, for other exceptions, continue throwing
if (RestStatus.fromCode(e.getResponse().getStatusLine().getStatusCode()) != RestStatus.NOT_FOUND) {
throw e;
}
}
if (indexName != null) {
deleteIndex(indexName);
}
}

Expand Down

0 comments on commit 3ab98bf

Please sign in to comment.