Skip to content

Commit 2018fee

Browse files
committed
Fix flaky model tests in k-NN
Signed-off-by: Ryan Bogan <rbogan@amazon.com>
1 parent 2b963b4 commit 2018fee

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/test/java/org/opensearch/knn/indices/ModelDaoTests.java

+12-3
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111

1212
package org.opensearch.knn.indices;
1313

14-
import org.junit.AfterClass;
15-
import org.junit.Assert;
16-
import org.junit.BeforeClass;
14+
import org.junit.*;
15+
import org.mockito.MockedStatic;
1716
import org.opensearch.ExceptionsHelper;
1817
import org.opensearch.ResourceAlreadyExistsException;
1918
import org.opensearch.ResourceNotFoundException;
19+
import org.opensearch.cluster.ClusterChangedEvent;
2020
import org.opensearch.core.action.ActionListener;
2121
import org.opensearch.action.DocWriteResponse;
2222
import org.opensearch.action.StepListener;
@@ -46,6 +46,7 @@
4646
import org.opensearch.knn.plugin.transport.UpdateModelGraveyardAction;
4747
import org.opensearch.knn.plugin.transport.UpdateModelGraveyardRequest;
4848
import org.opensearch.core.rest.RestStatus;
49+
import org.opensearch.knn.training.TrainingJobClusterStateListener;
4950

5051
import java.io.IOException;
5152
import java.time.ZoneOffset;
@@ -57,6 +58,8 @@
5758
import java.util.concurrent.Executors;
5859
import java.util.concurrent.TimeUnit;
5960

61+
import static org.mockito.ArgumentMatchers.any;
62+
import static org.mockito.Mockito.*;
6063
import static org.opensearch.cluster.metadata.Metadata.builder;
6164
import static org.opensearch.knn.common.KNNConstants.DIMENSION;
6265
import static org.opensearch.knn.common.KNNConstants.KNN_ENGINE;
@@ -73,15 +76,21 @@ public class ModelDaoTests extends KNNSingleNodeTestCase {
7376

7477
private static ExecutorService modelGetterExecutor;
7578
private static final String FAILED = "failed";
79+
private static MockedStatic<TrainingJobClusterStateListener> trainingJobClusterStateListenerMockedStatic;
7680

7781
@BeforeClass
7882
public static void setup() {
7983
modelGetterExecutor = Executors.newSingleThreadExecutor();
84+
trainingJobClusterStateListenerMockedStatic = mockStatic(TrainingJobClusterStateListener.class);
85+
final TrainingJobClusterStateListener trainingJobClusterStateListener = mock(TrainingJobClusterStateListener.class);
86+
doNothing().when(trainingJobClusterStateListener).clusterChanged(any(ClusterChangedEvent.class));
87+
trainingJobClusterStateListenerMockedStatic.when(TrainingJobClusterStateListener::getInstance).thenReturn(trainingJobClusterStateListener);
8088
}
8189

8290
@AfterClass
8391
public static void teardown() {
8492
modelGetterExecutor.shutdown();
93+
trainingJobClusterStateListenerMockedStatic.close();
8594
}
8695

8796
public void testCreate() throws IOException, InterruptedException {

0 commit comments

Comments
 (0)