From c3de09fa124d12fbdc2ce011c83b94c34103bc6b Mon Sep 17 00:00:00 2001 From: Hailong Cui Date: Wed, 2 Apr 2025 14:29:59 +0800 Subject: [PATCH] add more logs to toubleshot flaky test (#3543) Signed-off-by: Hailong Cui (cherry picked from commit 5e67dc18b66c27dbbb6652d27c471de7cb99e27a) --- .../ml/tools/ToolIntegrationWithLLMTest.java | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/plugin/src/test/java/org/opensearch/ml/tools/ToolIntegrationWithLLMTest.java b/plugin/src/test/java/org/opensearch/ml/tools/ToolIntegrationWithLLMTest.java index 62a20966a7..3dea5b7433 100644 --- a/plugin/src/test/java/org/opensearch/ml/tools/ToolIntegrationWithLLMTest.java +++ b/plugin/src/test/java/org/opensearch/ml/tools/ToolIntegrationWithLLMTest.java @@ -19,6 +19,7 @@ import org.opensearch.core.rest.RestStatus; import org.opensearch.ml.common.MLModel; import org.opensearch.ml.common.model.MLModelState; +import org.opensearch.ml.common.utils.StringUtils; import org.opensearch.ml.rest.RestBaseAgentToolsIT; import org.opensearch.ml.utils.TestHelper; @@ -77,9 +78,9 @@ public void deleteModel() throws IOException { @SneakyThrows private void checkForModelUndeployedStatus(String modelId) { - Predicate condition = response -> { + Predicate condition = responseStr -> { try { - Map responseInMap = parseResponseToMap(response); + Map responseInMap = StringUtils.gson.fromJson(responseStr, Map.class); MLModelState state = MLModelState.from(responseInMap.get(MLModel.MODEL_STATE_FIELD).toString()); return MLModelState.UNDEPLOYED.equals(state); } catch (Exception e) { @@ -90,14 +91,23 @@ private void checkForModelUndeployedStatus(String modelId) { } @SneakyThrows - protected Response waitResponseMeetingCondition(String method, String endpoint, String jsonEntity, Predicate condition) { + protected Response waitResponseMeetingCondition(String method, String endpoint, String jsonEntity, Predicate condition) { for (int attempt = 1; attempt <= MAX_RETRIES; attempt++) { Response response = TestHelper.makeRequest(client(), method, endpoint, null, jsonEntity, null); assertEquals(RestStatus.OK, RestStatus.fromCode(response.getStatusLine().getStatusCode())); - if (condition.test(response)) { + String entityString = TestHelper.httpEntityToString(response.getEntity()); + if (condition.test(entityString)) { return response; } - logger.info("The {}-th attempt on {}:{} . response: {}", attempt, method, endpoint, response.toString()); + logger + .info( + "The {}-th attempt on {}:{} . response: {}, responseBody: {}", + attempt, + method, + endpoint, + response.toString(), + entityString + ); Thread.sleep(DEFAULT_TASK_RESULT_QUERY_INTERVAL_IN_MILLISECOND); } fail(