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

Fix flaky tests #1355

Merged
merged 16 commits into from
Jan 3, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import org.apache.hc.core5.http.io.entity.EntityUtils;
import org.junit.AfterClass;
import org.junit.Ignore;
import org.opensearch.action.search.SearchResponse;
import org.opensearch.client.Request;
import org.opensearch.client.Response;
Expand Down Expand Up @@ -55,7 +56,7 @@ public class ModelIT extends AbstractRestartUpgradeTestCase {
private static int DOC_ID_TEST_MODEL_INDEX = 0;
private static int DOC_ID_TEST_MODEL_INDEX_DEFAULT = 0;
private static final int DELAY_MILLI_SEC = 1000;
private static final int EXP_NUM_OF_MODELS = 3;
private static final int EXP_NUM_OF_MODELS = 2;
ryanbogan marked this conversation as resolved.
Show resolved Hide resolved
private static final int K = 5;
private static final int NUM_DOCS = 10;
private static final int NUM_DOCS_TEST_MODEL_INDEX = 100;
Expand Down Expand Up @@ -83,6 +84,7 @@ public void testKNNModel() throws Exception {
createKnnIndex(testIndex, modelIndexMapping(TEST_FIELD, TEST_MODEL_ID));
addKNNDocs(testIndex, TEST_FIELD, DIMENSIONS, DOC_ID, NUM_DOCS);
} else {
Thread.sleep(1000);
DOC_ID = NUM_DOCS;
addKNNDocs(testIndex, TEST_FIELD, DIMENSIONS, DOC_ID, NUM_DOCS);
QUERY_COUNT = 2 * NUM_DOCS;
Expand Down Expand Up @@ -115,6 +117,7 @@ public void testKNNModelDefault() throws Exception {
createKnnIndex(testIndex, modelIndexMapping(TEST_FIELD, TEST_MODEL_ID_DEFAULT));
addKNNDocs(testIndex, TEST_FIELD, DIMENSIONS, DOC_ID, NUM_DOCS);
} else {
Thread.sleep(1000);
DOC_ID = NUM_DOCS;
addKNNDocs(testIndex, TEST_FIELD, DIMENSIONS, DOC_ID, NUM_DOCS);
QUERY_COUNT = 2 * NUM_DOCS;
Expand All @@ -140,13 +143,14 @@ public void testKNNModelDefault() throws Exception {
}

// KNN Delete Model test for model in Training State
@Ignore
ryanbogan marked this conversation as resolved.
Show resolved Hide resolved
public void testDeleteTrainingModel() throws Exception {
byte[] testModelBlob = "hello".getBytes(StandardCharsets.UTF_8);
ModelMetadata testModelMetadata = getModelMetadata();
testModelMetadata.setState(ModelState.TRAINING);
if (isRunningAgainstOldCluster()) {
byte[] testModelBlob = "hello".getBytes(StandardCharsets.UTF_8);
ModelMetadata testModelMetadata = getModelMetadata();
testModelMetadata.setState(ModelState.TRAINING);
addModelToSystemIndex(TEST_MODEL_ID_TRAINING, testModelMetadata, testModelBlob);
} else {

ryanbogan marked this conversation as resolved.
Show resolved Hide resolved
String restURI = String.join("/", KNNPlugin.KNN_BASE_URI, MODELS, TEST_MODEL_ID_TRAINING);
Request request = new Request("DELETE", restURI);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@

package org.opensearch.knn.plugin.transport;

import org.junit.BeforeClass;
import org.mockito.MockedStatic;
import org.opensearch.Version;
import org.opensearch.common.io.stream.BytesStreamOutput;
import org.opensearch.core.xcontent.XContentBuilder;
import org.opensearch.common.xcontent.XContentFactory;
import org.opensearch.knn.KNNTestCase;
import org.opensearch.knn.index.KNNClusterUtil;
import org.opensearch.knn.index.SpaceType;
import org.opensearch.knn.index.util.KNNEngine;
import org.opensearch.knn.indices.Model;
Expand All @@ -23,8 +27,22 @@

import java.io.IOException;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.mockStatic;
import static org.mockito.Mockito.when;

public class GetModelResponseTests extends KNNTestCase {

private static MockedStatic<KNNClusterUtil> knnClusterUtilMockedStatic;

@BeforeClass
public static void setup() {
ryanbogan marked this conversation as resolved.
Show resolved Hide resolved
final KNNClusterUtil knnClusterUtil = mock(KNNClusterUtil.class);
knnClusterUtilMockedStatic = mockStatic(KNNClusterUtil.class);
when(knnClusterUtil.getClusterMinVersion()).thenReturn(Version.CURRENT);
knnClusterUtilMockedStatic.when(KNNClusterUtil::instance).thenReturn(knnClusterUtil);
}

private ModelMetadata getModelMetadata(ModelState state) {
return new ModelMetadata(KNNEngine.DEFAULT, SpaceType.DEFAULT, 4, state, "2021-03-27 10:15:30 AM +05:30", "test model", "", "");
}
Expand Down
Loading