Skip to content

Commit 5e67dc1

Browse files
authored
add more logs to toubleshot flaky test (#3543)
Signed-off-by: Hailong Cui <ihailong@amazon.com>
1 parent c556efd commit 5e67dc1

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

plugin/src/test/java/org/opensearch/ml/tools/ToolIntegrationWithLLMTest.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.opensearch.core.rest.RestStatus;
2121
import org.opensearch.ml.common.MLModel;
2222
import org.opensearch.ml.common.model.MLModelState;
23+
import org.opensearch.ml.common.utils.StringUtils;
2324
import org.opensearch.ml.rest.RestBaseAgentToolsIT;
2425
import org.opensearch.ml.utils.TestHelper;
2526

@@ -77,9 +78,9 @@ public void deleteModel() throws IOException {
7778

7879
@SneakyThrows
7980
private void checkForModelUndeployedStatus(String modelId) {
80-
Predicate<Response> condition = response -> {
81+
Predicate<String> condition = responseStr -> {
8182
try {
82-
Map<String, Object> responseInMap = parseResponseToMap(response);
83+
Map<String, Object> responseInMap = StringUtils.gson.fromJson(responseStr, Map.class);
8384
MLModelState state = MLModelState.from(responseInMap.get(MLModel.MODEL_STATE_FIELD).toString());
8485
return MLModelState.UNDEPLOYED.equals(state);
8586
} catch (Exception e) {
@@ -90,14 +91,23 @@ private void checkForModelUndeployedStatus(String modelId) {
9091
}
9192

9293
@SneakyThrows
93-
protected Response waitResponseMeetingCondition(String method, String endpoint, String jsonEntity, Predicate<Response> condition) {
94+
protected Response waitResponseMeetingCondition(String method, String endpoint, String jsonEntity, Predicate<String> condition) {
9495
for (int attempt = 1; attempt <= MAX_RETRIES; attempt++) {
9596
Response response = TestHelper.makeRequest(client(), method, endpoint, null, jsonEntity, null);
9697
assertEquals(RestStatus.OK, RestStatus.fromCode(response.getStatusLine().getStatusCode()));
97-
if (condition.test(response)) {
98+
String entityString = TestHelper.httpEntityToString(response.getEntity());
99+
if (condition.test(entityString)) {
98100
return response;
99101
}
100-
logger.info("The {}-th attempt on {}:{} . response: {}", attempt, method, endpoint, response.toString());
102+
logger
103+
.info(
104+
"The {}-th attempt on {}:{} . response: {}, responseBody: {}",
105+
attempt,
106+
method,
107+
endpoint,
108+
response.toString(),
109+
entityString
110+
);
101111
Thread.sleep(DEFAULT_TASK_RESULT_QUERY_INTERVAL_IN_MILLISECOND);
102112
}
103113
fail(

0 commit comments

Comments
 (0)