Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more logs to troubleshot flaky test #3543

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,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;

Expand Down Expand Up @@ -77,9 +78,9 @@ public void deleteModel() throws IOException {

@SneakyThrows
private void checkForModelUndeployedStatus(String modelId) {
Predicate<Response> condition = response -> {
Predicate<String> condition = responseStr -> {
try {
Map<String, Object> responseInMap = parseResponseToMap(response);
Map<String, Object> 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) {
Expand All @@ -90,14 +91,23 @@ private void checkForModelUndeployedStatus(String modelId) {
}

@SneakyThrows
protected Response waitResponseMeetingCondition(String method, String endpoint, String jsonEntity, Predicate<Response> condition) {
protected Response waitResponseMeetingCondition(String method, String endpoint, String jsonEntity, Predicate<String> 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(
Expand Down