Skip to content

Commit 2934488

Browse files
authored
ESQL: Speed up semantic_text tests (elastic#128591) (elastic#128593)
Speeds up the semantic_text tests by using a test inference plugin. That skips downloading the normal inference setup. Closes elastic#128511 Closes elastic#128513 Closes elastic#128571 Closes elastic#128572 Closes elastic#128573 Closes elastic#128574
1 parent a014191 commit 2934488

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;
@@ -51,10 +50,9 @@
5150
* Tests for pushing queries to lucene.
5251
*/
5352
@ThreadLeakFilters(filters = TestClustersThreadFilter.class)
54-
@TimeoutSuite(millis = 10 * TimeUnits.MINUTE) // semantic_text can take a long, long time to start in CI
5553
public class PushQueriesIT extends ESRestTestCase {
5654
@ClassRule
57-
public static ElasticsearchCluster cluster = Clusters.testCluster();
55+
public static ElasticsearchCluster cluster = Clusters.testCluster(spec -> spec.plugin("inference-service-test"));
5856

5957
@ParametersFactory(argumentFormatting = "%1s")
6058
public static List<Object[]> args() {
@@ -288,13 +286,30 @@ private void indexValue(String value) throws IOException {
288286
"number_of_shards": 1
289287
}
290288
}""";
291-
if (false == "auto".equals(type)) {
292-
json += """
289+
json += switch (type) {
290+
case "auto" -> "";
291+
case "semantic_text" -> """
293292
,
294293
"mappings": {
295294
"properties": {
296295
"test": {
297-
"type": "%type",
296+
"type": "semantic_text",
297+
"inference_id": "test",
298+
"fields": {
299+
"keyword": {
300+
"type": "keyword",
301+
"ignore_above": 256
302+
}
303+
}
304+
}
305+
}
306+
}""";
307+
default -> """
308+
,
309+
"mappings": {
310+
"properties": {
311+
"test": {
312+
"type": "%type",
298313
"fields": {
299314
"keyword": {
300315
"type": "keyword",
@@ -305,7 +320,7 @@ private void indexValue(String value) throws IOException {
305320
}
306321
}
307322
}""".replace("%type", type);
308-
}
323+
};
309324
json += "}";
310325
createIndex.setJsonEntity(json);
311326
Response createResponse = client().performRequest(createIndex);
@@ -347,4 +362,28 @@ protected boolean preserveClusterUponCompletion() {
347362
// Preserve the cluser to speed up the semantic_text tests
348363
return true;
349364
}
365+
366+
private static boolean setupEmbeddings = false;
367+
368+
@Before
369+
public void setUpTextEmbeddingInferenceEndpoint() throws IOException {
370+
if (type.equals("semantic_text") == false || setupEmbeddings) {
371+
return;
372+
}
373+
setupEmbeddings = true;
374+
Request request = new Request("PUT", "_inference/text_embedding/test");
375+
request.setJsonEntity("""
376+
{
377+
"service": "text_embedding_test_service",
378+
"service_settings": {
379+
"model": "my_model",
380+
"api_key": "abc64",
381+
"dimensions": 128
382+
},
383+
"task_settings": {
384+
}
385+
}
386+
""");
387+
adminClient().performRequest(request);
388+
}
350389
}

0 commit comments

Comments
 (0)