Skip to content

Commit d507b26

Browse files
authored
ESQL: Speed up spec tests (#131949)
Speeds up the spec tests by: * Randomize `async`/`sync` instead of both * Check the took time rarely * Don't check if index exists every time * Reduce transfer when checking breaker * Cache capabilities checks The first one is most of the speed up but the rest save another couple of minutes. Time drops from 13m45s to 6m or so on my laptop.
1 parent 593f48f commit d507b26

File tree

13 files changed

+101
-148
lines changed

13 files changed

+101
-148
lines changed

x-pack/plugin/esql/qa/security/src/javaRestTest/java/org/elasticsearch/xpack/esql/EsqlSecurityIT.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import org.elasticsearch.xcontent.XContentBuilder;
2828
import org.elasticsearch.xcontent.json.JsonXContent;
2929
import org.elasticsearch.xpack.esql.action.EsqlCapabilities;
30-
import org.elasticsearch.xpack.esql.qa.rest.EsqlSpecTestCase;
3130
import org.junit.Before;
3231
import org.junit.ClassRule;
3332

@@ -40,6 +39,7 @@
4039
import static org.elasticsearch.test.ListMatcher.matchesList;
4140
import static org.elasticsearch.test.MapMatcher.assertMap;
4241
import static org.elasticsearch.test.MapMatcher.matchesMap;
42+
import static org.elasticsearch.xpack.esql.qa.rest.RestEsqlTestCase.hasCapabilities;
4343
import static org.hamcrest.Matchers.containsString;
4444
import static org.hamcrest.Matchers.equalTo;
4545
import static org.hamcrest.Matchers.is;
@@ -594,7 +594,7 @@ record Listen(long timestamp, String songId, double duration) {
594594
public void testLookupJoinIndexAllowed() throws Exception {
595595
assumeTrue(
596596
"Requires LOOKUP JOIN capability",
597-
EsqlSpecTestCase.hasCapabilities(adminClient(), List.of(EsqlCapabilities.Cap.JOIN_LOOKUP_V12.capabilityName()))
597+
hasCapabilities(adminClient(), List.of(EsqlCapabilities.Cap.JOIN_LOOKUP_V12.capabilityName()))
598598
);
599599

600600
Response resp = runESQLCommand(
@@ -685,7 +685,7 @@ public void testLookupJoinIndexAllowed() throws Exception {
685685
public void testLookupJoinDocLevelSecurity() throws Exception {
686686
assumeTrue(
687687
"Requires LOOKUP JOIN capability",
688-
EsqlSpecTestCase.hasCapabilities(adminClient(), List.of(EsqlCapabilities.Cap.JOIN_LOOKUP_V12.capabilityName()))
688+
hasCapabilities(adminClient(), List.of(EsqlCapabilities.Cap.JOIN_LOOKUP_V12.capabilityName()))
689689
);
690690

691691
Response resp = runESQLCommand("dls_user", "ROW x = 40.0 | EVAL value = x | LOOKUP JOIN lookup-user2 ON value | KEEP x, org");
@@ -734,7 +734,7 @@ public void testLookupJoinDocLevelSecurity() throws Exception {
734734
public void testLookupJoinFieldLevelSecurity() throws Exception {
735735
assumeTrue(
736736
"Requires LOOKUP JOIN capability",
737-
EsqlSpecTestCase.hasCapabilities(adminClient(), List.of(EsqlCapabilities.Cap.JOIN_LOOKUP_V12.capabilityName()))
737+
hasCapabilities(adminClient(), List.of(EsqlCapabilities.Cap.JOIN_LOOKUP_V12.capabilityName()))
738738
);
739739

740740
Response resp = runESQLCommand("fls_user2", "ROW x = 40.0 | EVAL value = x | LOOKUP JOIN lookup-user2 ON value");
@@ -792,7 +792,7 @@ public void testLookupJoinFieldLevelSecurity() throws Exception {
792792
public void testLookupJoinFieldLevelSecurityOnAlias() throws Exception {
793793
assumeTrue(
794794
"Requires LOOKUP JOIN capability",
795-
EsqlSpecTestCase.hasCapabilities(adminClient(), List.of(EsqlCapabilities.Cap.JOIN_LOOKUP_V12.capabilityName()))
795+
hasCapabilities(adminClient(), List.of(EsqlCapabilities.Cap.JOIN_LOOKUP_V12.capabilityName()))
796796
);
797797

798798
Response resp = runESQLCommand("fls_user2_alias", "ROW x = 40.0 | EVAL value = x | LOOKUP JOIN lookup-second-alias ON value");
@@ -850,7 +850,7 @@ public void testLookupJoinFieldLevelSecurityOnAlias() throws Exception {
850850
public void testLookupJoinIndexForbidden() throws Exception {
851851
assumeTrue(
852852
"Requires LOOKUP JOIN capability",
853-
EsqlSpecTestCase.hasCapabilities(adminClient(), List.of(EsqlCapabilities.Cap.JOIN_LOOKUP_V12.capabilityName()))
853+
hasCapabilities(adminClient(), List.of(EsqlCapabilities.Cap.JOIN_LOOKUP_V12.capabilityName()))
854854
);
855855

856856
var resp = expectThrows(

x-pack/plugin/esql/qa/server/mixed-cluster/src/javaRestTest/java/org/elasticsearch/xpack/esql/qa/mixed/MixedClusterEsqlSpecIT.java

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import org.elasticsearch.test.rest.TestFeatureService;
1313
import org.elasticsearch.xpack.esql.CsvSpecReader.CsvTestCase;
1414
import org.elasticsearch.xpack.esql.qa.rest.EsqlSpecTestCase;
15-
import org.elasticsearch.xpack.esql.qa.rest.RestEsqlTestCase.Mode;
1615
import org.junit.AfterClass;
1716
import org.junit.Before;
1817
import org.junit.ClassRule;
@@ -22,6 +21,7 @@
2221

2322
import static org.elasticsearch.xpack.esql.CsvTestUtils.isEnabled;
2423
import static org.elasticsearch.xpack.esql.action.EsqlCapabilities.Cap.JOIN_LOOKUP_V12;
24+
import static org.elasticsearch.xpack.esql.qa.rest.RestEsqlTestCase.hasCapabilities;
2525

2626
public class MixedClusterEsqlSpecIT extends EsqlSpecTestCase {
2727
@ClassRule
@@ -43,11 +43,6 @@ public void extractOldClusterFeatures() {
4343
}
4444
}
4545

46-
protected static boolean oldClusterHasFeature(String featureId) {
47-
assert oldClusterTestFeatureService != null;
48-
return oldClusterTestFeatureService.clusterHasFeature(featureId);
49-
}
50-
5146
@AfterClass
5247
public static void cleanUp() {
5348
oldClusterTestFeatureService = null;
@@ -59,10 +54,9 @@ public MixedClusterEsqlSpecIT(
5954
String testName,
6055
Integer lineNumber,
6156
CsvTestCase testCase,
62-
String instructions,
63-
Mode mode
57+
String instructions
6458
) {
65-
super(fileName, groupName, testName, lineNumber, testCase, instructions, mode);
59+
super(fileName, groupName, testName, lineNumber, testCase, instructions);
6660
}
6761

6862
@Override
@@ -87,12 +81,12 @@ protected boolean supportsInferenceTestService() {
8781
}
8882

8983
@Override
90-
protected boolean supportsIndexModeLookup() throws IOException {
91-
return hasCapabilities(List.of(JOIN_LOOKUP_V12.capabilityName()));
84+
protected boolean supportsIndexModeLookup() {
85+
return hasCapabilities(adminClient(), List.of(JOIN_LOOKUP_V12.capabilityName()));
9286
}
9387

9488
@Override
95-
protected boolean supportsSourceFieldMapping() throws IOException {
89+
protected boolean supportsSourceFieldMapping() {
9690
return false;
9791
}
9892

x-pack/plugin/esql/qa/server/multi-clusters/src/javaRestTest/java/org/elasticsearch/xpack/esql/ccq/MultiClusterSpecIT.java

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import org.elasticsearch.xpack.esql.CsvTestsDataLoader;
2828
import org.elasticsearch.xpack.esql.SpecReader;
2929
import org.elasticsearch.xpack.esql.qa.rest.EsqlSpecTestCase;
30-
import org.elasticsearch.xpack.esql.qa.rest.RestEsqlTestCase.Mode;
3130
import org.junit.AfterClass;
3231
import org.junit.ClassRule;
3332
import org.junit.rules.RuleChain;
@@ -36,7 +35,6 @@
3635
import java.io.ByteArrayInputStream;
3736
import java.io.IOException;
3837
import java.net.URL;
39-
import java.util.ArrayList;
4038
import java.util.Arrays;
4139
import java.util.List;
4240
import java.util.Locale;
@@ -58,7 +56,7 @@
5856
import static org.elasticsearch.xpack.esql.action.EsqlCapabilities.Cap.JOIN_PLANNING_V1;
5957
import static org.elasticsearch.xpack.esql.action.EsqlCapabilities.Cap.METADATA_FIELDS_REMOTE_TEST;
6058
import static org.elasticsearch.xpack.esql.action.EsqlCapabilities.Cap.UNMAPPED_FIELDS;
61-
import static org.elasticsearch.xpack.esql.qa.rest.RestEsqlTestCase.Mode.SYNC;
59+
import static org.elasticsearch.xpack.esql.qa.rest.RestEsqlTestCase.hasCapabilities;
6260
import static org.mockito.ArgumentMatchers.any;
6361
import static org.mockito.Mockito.doAnswer;
6462
import static org.mockito.Mockito.mock;
@@ -86,19 +84,7 @@ public class MultiClusterSpecIT extends EsqlSpecTestCase {
8684
public static List<Object[]> readScriptSpec() throws Exception {
8785
List<URL> urls = classpathResources("/*.csv-spec");
8886
assertTrue("Not enough specs found " + urls, urls.size() > 0);
89-
List<Object[]> specs = SpecReader.readScriptSpec(urls, specParser());
90-
91-
int len = specs.get(0).length;
92-
List<Object[]> testcases = new ArrayList<>();
93-
for (var spec : specs) {
94-
for (Mode mode : List.of(SYNC)) { // No async, for now
95-
Object[] obj = new Object[len + 1];
96-
System.arraycopy(spec, 0, obj, 0, len);
97-
obj[len] = mode;
98-
testcases.add(obj);
99-
}
100-
}
101-
return testcases;
87+
return SpecReader.readScriptSpec(urls, specParser());
10288
}
10389

10490
public MultiClusterSpecIT(
@@ -107,10 +93,9 @@ public MultiClusterSpecIT(
10793
String testName,
10894
Integer lineNumber,
10995
CsvTestCase testCase,
110-
String instructions,
111-
Mode mode
96+
String instructions
11297
) {
113-
super(fileName, groupName, testName, lineNumber, convertToRemoteIndices(testCase), instructions, mode);
98+
super(fileName, groupName, testName, lineNumber, convertToRemoteIndices(testCase), instructions);
11499
}
115100

116101
// TODO: think how to handle this better
@@ -152,7 +137,10 @@ protected void shouldSkipTest(String testName) throws IOException {
152137
assumeFalse("INLINESTATS not yet supported in CCS", testCase.requiredCapabilities.contains(JOIN_PLANNING_V1.capabilityName()));
153138
assumeFalse("INLINESTATS not yet supported in CCS", testCase.requiredCapabilities.contains(INLINESTATS_V9.capabilityName()));
154139
if (testCase.requiredCapabilities.contains(JOIN_LOOKUP_V12.capabilityName())) {
155-
assumeTrue("LOOKUP JOIN not yet supported in CCS", hasCapabilities(List.of(ENABLE_LOOKUP_JOIN_ON_REMOTE.capabilityName())));
140+
assumeTrue(
141+
"LOOKUP JOIN not yet supported in CCS",
142+
hasCapabilities(adminClient(), List.of(ENABLE_LOOKUP_JOIN_ON_REMOTE.capabilityName()))
143+
);
156144
}
157145
// Unmapped fields require a coorect capability response from every cluster, which isn't currently implemented.
158146
assumeFalse("UNMAPPED FIELDS not yet supported in CCS", testCase.requiredCapabilities.contains(UNMAPPED_FIELDS.capabilityName()));
@@ -401,7 +389,7 @@ protected boolean supportsInferenceTestService() {
401389

402390
@Override
403391
protected boolean supportsIndexModeLookup() throws IOException {
404-
return hasCapabilities(List.of(JOIN_LOOKUP_V12.capabilityName()));
392+
return hasCapabilities(adminClient(), List.of(JOIN_LOOKUP_V12.capabilityName()));
405393
}
406394

407395
@Override

x-pack/plugin/esql/qa/server/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/esql/qa/multi_node/EsqlSpecIT.java

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import org.elasticsearch.test.cluster.ElasticsearchCluster;
1111
import org.elasticsearch.xpack.esql.CsvSpecReader.CsvTestCase;
1212
import org.elasticsearch.xpack.esql.qa.rest.EsqlSpecTestCase;
13-
import org.elasticsearch.xpack.esql.qa.rest.RestEsqlTestCase.Mode;
1413
import org.junit.ClassRule;
1514

1615
import java.io.IOException;
@@ -24,16 +23,8 @@ protected String getTestRestCluster() {
2423
return cluster.getHttpAddresses();
2524
}
2625

27-
public EsqlSpecIT(
28-
String fileName,
29-
String groupName,
30-
String testName,
31-
Integer lineNumber,
32-
CsvTestCase testCase,
33-
String instructions,
34-
Mode mode
35-
) {
36-
super(fileName, groupName, testName, lineNumber, testCase, instructions, mode);
26+
public EsqlSpecIT(String fileName, String groupName, String testName, Integer lineNumber, CsvTestCase testCase, String instructions) {
27+
super(fileName, groupName, testName, lineNumber, testCase, instructions);
3728
}
3829

3930
@Override

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

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import org.elasticsearch.xpack.esql.planner.PhysicalSettings;
2020
import org.elasticsearch.xpack.esql.plugin.ComputeService;
2121
import org.elasticsearch.xpack.esql.qa.rest.EsqlSpecTestCase;
22-
import org.elasticsearch.xpack.esql.qa.rest.RestEsqlTestCase.Mode;
2322
import org.junit.Before;
2423
import org.junit.ClassRule;
2524

@@ -37,16 +36,8 @@ protected String getTestRestCluster() {
3736
return cluster.getHttpAddresses();
3837
}
3938

40-
public EsqlSpecIT(
41-
String fileName,
42-
String groupName,
43-
String testName,
44-
Integer lineNumber,
45-
CsvTestCase testCase,
46-
String instructions,
47-
Mode mode
48-
) {
49-
super(fileName, groupName, testName, lineNumber, testCase, instructions, mode);
39+
public EsqlSpecIT(String fileName, String groupName, String testName, Integer lineNumber, CsvTestCase testCase, String instructions) {
40+
super(fileName, groupName, testName, lineNumber, testCase, instructions);
5041
}
5142

5243
@Override

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import org.elasticsearch.test.TestClustersThreadFilter;
1313
import org.elasticsearch.test.cluster.ElasticsearchCluster;
1414
import org.elasticsearch.xpack.esql.CsvSpecReader;
15-
import org.elasticsearch.xpack.esql.qa.rest.RestEsqlTestCase.Mode;
1615
import org.elasticsearch.xpack.esql.qa.rest.generative.GenerativeForkRestTest;
1716
import org.junit.ClassRule;
1817

@@ -32,10 +31,9 @@ public GenerativeForkIT(
3231
String testName,
3332
Integer lineNumber,
3433
CsvSpecReader.CsvTestCase testCase,
35-
String instructions,
36-
Mode mode
34+
String instructions
3735
) {
38-
super(fileName, groupName, testName, lineNumber, testCase, instructions, mode);
36+
super(fileName, groupName, testName, lineNumber, testCase, instructions);
3937
}
4038

4139
@Override

0 commit comments

Comments
 (0)