Skip to content

Commit e9d7d4f

Browse files
committed
ESQL: Speed up semantic_text tests
Speeds up the semantic_text tests by using a test inference plugin. That skips downloading the normal inference setup.
1 parent c2ad34b commit e9d7d4f

File tree

1 file changed

+47
-8
lines changed
  • x-pack/plugin/esql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/esql/qa/single_node

1 file changed

+47
-8
lines changed

x-pack/plugin/esql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/esql/qa/single_node/PushQueriesIT.java

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99

1010
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
1111
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakFilters;
12-
import com.carrotsearch.randomizedtesting.annotations.TimeoutSuite;
1312

14-
import org.apache.lucene.tests.util.TimeUnits;
1513
import org.elasticsearch.client.Request;
1614
import org.elasticsearch.client.Response;
1715
import org.elasticsearch.client.ResponseException;
@@ -25,6 +23,7 @@
2523
import org.elasticsearch.xpack.esql.AssertWarnings;
2624
import org.elasticsearch.xpack.esql.qa.rest.RestEsqlTestCase;
2725
import org.hamcrest.Matcher;
26+
import org.junit.Before;
2827
import org.junit.ClassRule;
2928

3029
import java.io.IOException;
@@ -52,10 +51,9 @@
5251
* Tests for pushing queries to lucene.
5352
*/
5453
@ThreadLeakFilters(filters = TestClustersThreadFilter.class)
55-
@TimeoutSuite(millis = 10 * TimeUnits.MINUTE) // semantic_text can take a long, long time to start in CI
5654
public class PushQueriesIT extends ESRestTestCase {
5755
@ClassRule
58-
public static ElasticsearchCluster cluster = Clusters.testCluster();
56+
public static ElasticsearchCluster cluster = Clusters.testCluster(spec -> spec.plugin("inference-service-test"));
5957

6058
@ParametersFactory(argumentFormatting = "%1s")
6159
public static List<Object[]> args() {
@@ -294,13 +292,30 @@ private void indexValue(String value) throws IOException {
294292
"number_of_shards": 1
295293
}
296294
}""";
297-
if (false == "auto".equals(type)) {
298-
json += """
295+
json += switch (type) {
296+
case "auto" -> "";
297+
case "semantic_text" -> """
299298
,
300299
"mappings": {
301300
"properties": {
302301
"test": {
303-
"type": "%type",
302+
"type": "semantic_text",
303+
"inference_id": "test",
304+
"fields": {
305+
"keyword": {
306+
"type": "keyword",
307+
"ignore_above": 256
308+
}
309+
}
310+
}
311+
}
312+
}""";
313+
default -> """
314+
,
315+
"mappings": {
316+
"properties": {
317+
"test": {
318+
"type": "%type",
304319
"fields": {
305320
"keyword": {
306321
"type": "keyword",
@@ -311,7 +326,7 @@ private void indexValue(String value) throws IOException {
311326
}
312327
}
313328
}""".replace("%type", type);
314-
}
329+
};
315330
json += "}";
316331
createIndex.setJsonEntity(json);
317332
Response createResponse = client().performRequest(createIndex);
@@ -353,4 +368,28 @@ protected boolean preserveClusterUponCompletion() {
353368
// Preserve the cluser to speed up the semantic_text tests
354369
return true;
355370
}
371+
372+
private static boolean setupEmbeddings = false;
373+
374+
@Before
375+
public void setUpTextEmbeddingInferenceEndpoint() throws IOException {
376+
if (type.equals("semantic_text") == false || setupEmbeddings) {
377+
return;
378+
}
379+
setupEmbeddings = true;
380+
Request request = new Request("PUT", "_inference/text_embedding/test");
381+
request.setJsonEntity("""
382+
{
383+
"service": "text_embedding_test_service",
384+
"service_settings": {
385+
"model": "my_model",
386+
"api_key": "abc64",
387+
"dimensions": 128
388+
},
389+
"task_settings": {
390+
}
391+
}
392+
""");
393+
adminClient().performRequest(request);
394+
}
356395
}

0 commit comments

Comments
 (0)