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

[Refactor] Remove bloat due to unnecessary setup in test and add retry for potential flaky behavior due to timeout #3259

Merged
Merged
Changes from 1 commit
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 @@ -5,38 +5,47 @@

package org.opensearch.ml.action.models;

import org.junit.Before;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.rules.ExpectedException;
import org.opensearch.OpenSearchTimeoutException;
import org.opensearch.action.ActionRequestValidationException;
import org.opensearch.ml.action.MLCommonsIntegTestCase;
import org.opensearch.ml.common.MLModel;
import org.opensearch.ml.common.exception.MLResourceNotFoundException;
import org.opensearch.test.OpenSearchIntegTestCase;

@OpenSearchIntegTestCase.ClusterScope(scope = OpenSearchIntegTestCase.Scope.SUITE, numDataNodes = 2)
public class GetModelITTests extends MLCommonsIntegTestCase {
private String irisIndexName;

@Rule
public ExpectedException exceptionRule = ExpectedException.none();
private static final int MAX_RETRIES = 3;

@Before
public void setUp() throws Exception {
super.setUp();
irisIndexName = "iris_data_for_model_it";
loadIrisData(irisIndexName);
}

@Ignore
public void testGetModel_IndexNotFound() {
exceptionRule.expect(MLResourceNotFoundException.class);
MLModel model = getModel("test_id");
testGetModelExceptionsWithRetry(MLResourceNotFoundException.class, "test_id");
}

public void testGetModel_NullModelIdException() {
exceptionRule.expect(ActionRequestValidationException.class);
MLModel model = getModel(null);
testGetModelExceptionsWithRetry(ActionRequestValidationException.class, null);
}

private void testGetModelExceptionsWithRetry(Class<? extends Exception> expectedException, String modelId) {
pyek-bot marked this conversation as resolved.
Show resolved Hide resolved
assertThrows(expectedException, () -> {
for (int retryAttempt = 1; retryAttempt <= MAX_RETRIES; retryAttempt++) {
try {
getModel(modelId);
} catch (OpenSearchTimeoutException e) {
logger.info("GetModelITTests attempt: {}", retryAttempt);

if (retryAttempt == MAX_RETRIES) {
logger.error("Failed to execute test GetModelITTests after {} retries due to timeout", MAX_RETRIES);
throw e;
}

// adding small delay between retries
try {
Thread.sleep(1000);
} catch (InterruptedException ie) {
Thread.currentThread().interrupt();
throw new RuntimeException("Thread was interrupted during retry", ie);
}
}
}
});
}
}
Loading