Skip to content

Commit 25dce72

Browse files
Add response before each test file for eis
1 parent 77595cb commit 25dce72

File tree

4 files changed

+26
-19
lines changed

4 files changed

+26
-19
lines changed

x-pack/plugin/inference/qa/inference-service-tests/src/javaRestTest/java/org/elasticsearch/xpack/inference/BaseMockEISAuthServerTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,12 @@ public class BaseMockEISAuthServerTest extends ESRestTestCase {
2727
// authorization response and running the test. Retrieving the authorization should be very fast since
2828
// we're hosting a local mock server but it's possible it could respond slower. So in the even of a test failure
2929
// we'll automatically retry after waiting a second.
30+
// Note: @Rule is executed for each test
3031
@Rule
3132
public RetryRule retry = new RetryRule(3, TimeValue.timeValueSeconds(1));
3233

33-
private static final MockElasticInferenceServiceAuthorizationServer mockEISServer = MockElasticInferenceServiceAuthorizationServer
34-
.enabledWithRainbowSprinklesAndElser();
34+
protected static final MockElasticInferenceServiceAuthorizationServer mockEISServer =
35+
new MockElasticInferenceServiceAuthorizationServer();
3536

3637
private static final ElasticsearchCluster cluster = ElasticsearchCluster.local()
3738
.distribution(DistributionType.DEFAULT)
@@ -50,6 +51,7 @@ public class BaseMockEISAuthServerTest extends ESRestTestCase {
5051

5152
// The reason we're doing this is to make sure the mock server is initialized first so we can get the address before communicating
5253
// it to the cluster as a setting.
54+
// Note: @ClassRule is executed once for the entire test class
5355
@ClassRule
5456
public static TestRule ruleChain = RuleChain.outerRule(mockEISServer).around(cluster);
5557

x-pack/plugin/inference/qa/inference-service-tests/src/javaRestTest/java/org/elasticsearch/xpack/inference/InferenceGetModelsWithElasticInferenceServiceIT.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
package org.elasticsearch.xpack.inference;
1111

1212
import org.elasticsearch.inference.TaskType;
13+
import org.junit.BeforeClass;
1314

1415
import java.io.IOException;
1516
import java.util.List;
@@ -22,6 +23,12 @@
2223

2324
public class InferenceGetModelsWithElasticInferenceServiceIT extends BaseMockEISAuthServerTest {
2425

26+
@BeforeClass
27+
public static void init() {
28+
// Ensure the mock EIS server has an authorized response ready
29+
mockEISServer.enqueueAuthorizeAllModelsResponse();
30+
}
31+
2532
public void testGetDefaultEndpoints() throws IOException {
2633
var allModels = getAllModels();
2734
var chatCompletionModels = getModels("_all", TaskType.CHAT_COMPLETION);

x-pack/plugin/inference/qa/inference-service-tests/src/javaRestTest/java/org/elasticsearch/xpack/inference/InferenceGetServicesIT.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.elasticsearch.client.Request;
1313
import org.elasticsearch.common.Strings;
1414
import org.elasticsearch.inference.TaskType;
15+
import org.junit.BeforeClass;
1516

1617
import java.io.IOException;
1718
import java.util.List;
@@ -23,6 +24,12 @@
2324

2425
public class InferenceGetServicesIT extends BaseMockEISAuthServerTest {
2526

27+
@BeforeClass
28+
public static void init() {
29+
// Ensure the mock EIS server has an authorized response ready
30+
mockEISServer.enqueueAuthorizeAllModelsResponse();
31+
}
32+
2633
public void testGetServicesWithoutTaskType() throws IOException {
2734
List<Object> services = getAllServices();
2835
assertThat(services.size(), equalTo(22));
@@ -101,7 +108,7 @@ public void testGetServicesWithTextEmbeddingTaskType() throws IOException {
101108

102109
public void testGetServicesWithRerankTaskType() throws IOException {
103110
List<Object> services = getServices(TaskType.RERANK);
104-
assertThat(services.size(), equalTo(8));
111+
assertThat(services.size(), equalTo(9));
105112

106113
var providers = providers(services);
107114

@@ -124,7 +131,7 @@ public void testGetServicesWithRerankTaskType() throws IOException {
124131

125132
public void testGetServicesWithCompletionTaskType() throws IOException {
126133
List<Object> services = getServices(TaskType.COMPLETION);
127-
assertThat(services.size(), equalTo(12));
134+
assertThat(services.size(), equalTo(13));
128135

129136
var providers = providers(services);
130137

x-pack/plugin/inference/qa/inference-service-tests/src/javaRestTest/java/org/elasticsearch/xpack/inference/MockElasticInferenceServiceAuthorizationServer.java

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ public class MockElasticInferenceServiceAuthorizationServer implements TestRule
2626
public static MockElasticInferenceServiceAuthorizationServer enabledWithRainbowSprinklesAndElser() {
2727
var server = new MockElasticInferenceServiceAuthorizationServer();
2828

29+
server.enqueueAuthorizeAllModelsResponse();
30+
return server;
31+
}
32+
33+
public void enqueueAuthorizeAllModelsResponse() {
2934
String responseJson = """
3035
{
3136
"models": [
@@ -41,21 +46,7 @@ public static MockElasticInferenceServiceAuthorizationServer enabledWithRainbowS
4146
}
4247
""";
4348

44-
server.webServer.enqueue(new MockResponse().setResponseCode(200).setBody(responseJson));
45-
return server;
46-
}
47-
48-
public static MockElasticInferenceServiceAuthorizationServer disabled() {
49-
var server = new MockElasticInferenceServiceAuthorizationServer();
50-
51-
String responseJson = """
52-
{
53-
"models": []
54-
}
55-
""";
56-
57-
server.webServer.enqueue(new MockResponse().setResponseCode(200).setBody(responseJson));
58-
return server;
49+
webServer.enqueue(new MockResponse().setResponseCode(200).setBody(responseJson));
5950
}
6051

6152
public String getUrl() {

0 commit comments

Comments
 (0)