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 model tests #1429

Merged
merged 4 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
* Upgrade gradle to 8.4 [1289](https://github.com/opensearch-project/k-NN/pull/1289)
* Refactor security testing to install from individual components [#1307](https://github.com/opensearch-project/k-NN/pull/1307)
* Refactor integ tests that access model index [#1423](https://github.com/opensearch-project/k-NN/pull/1423)
* Fix flaky model tests [#1429](https://github.com/opensearch-project/k-NN/pull/1429)
### Documentation
### Maintenance
* Update developer guide to include M1 Setup [#1222](https://github.com/opensearch-project/k-NN/pull/1222)
Expand Down
14 changes: 14 additions & 0 deletions src/test/java/org/opensearch/knn/indices/ModelDaoTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.mockito.MockedStatic;
import org.opensearch.ExceptionsHelper;
import org.opensearch.ResourceAlreadyExistsException;
import org.opensearch.ResourceNotFoundException;
import org.opensearch.cluster.ClusterChangedEvent;
import org.opensearch.core.action.ActionListener;
import org.opensearch.action.DocWriteResponse;
import org.opensearch.action.StepListener;
Expand Down Expand Up @@ -46,6 +48,7 @@
import org.opensearch.knn.plugin.transport.UpdateModelGraveyardAction;
import org.opensearch.knn.plugin.transport.UpdateModelGraveyardRequest;
import org.opensearch.core.rest.RestStatus;
import org.opensearch.knn.training.TrainingJobClusterStateListener;

import java.io.IOException;
import java.time.ZoneOffset;
Expand All @@ -57,6 +60,10 @@
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.mockStatic;
import static org.opensearch.cluster.metadata.Metadata.builder;
import static org.opensearch.knn.common.KNNConstants.DIMENSION;
import static org.opensearch.knn.common.KNNConstants.KNN_ENGINE;
Expand All @@ -73,15 +80,22 @@ public class ModelDaoTests extends KNNSingleNodeTestCase {

private static ExecutorService modelGetterExecutor;
private static final String FAILED = "failed";
private static MockedStatic<TrainingJobClusterStateListener> trainingJobClusterStateListenerMockedStatic;

@BeforeClass
public static void setup() {
modelGetterExecutor = Executors.newSingleThreadExecutor();
trainingJobClusterStateListenerMockedStatic = mockStatic(TrainingJobClusterStateListener.class);
final TrainingJobClusterStateListener trainingJobClusterStateListener = mock(TrainingJobClusterStateListener.class);
doNothing().when(trainingJobClusterStateListener).clusterChanged(any(ClusterChangedEvent.class));
trainingJobClusterStateListenerMockedStatic.when(TrainingJobClusterStateListener::getInstance)
.thenReturn(trainingJobClusterStateListener);
}

@AfterClass
public static void teardown() {
modelGetterExecutor.shutdown();
trainingJobClusterStateListenerMockedStatic.close();
}

public void testCreate() throws IOException, InterruptedException {
Expand Down
Loading