Skip to content

Commit

Permalink
ESQL: Allow tests to depend on cluster features (elastic#106271)
Browse files Browse the repository at this point in the history
This allows writing `required_feature:` in a test to skip the test on
versions of elasticsearch that are missing a feature, opting ESQL into
the same versioning as the yaml tests.
  • Loading branch information
nik9000 authored Mar 13, 2024
1 parent 2a87081 commit 146d13c
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ public final void test() throws Throwable {
}

protected void shouldSkipTest(String testName) {
for (String feature : testCase.requiredFeatures) {
assumeTrue("Test " + testName + " requires " + feature, clusterHasFeature(feature));
}
assumeTrue("Test " + testName + " is not enabled", isEnabled(testName, Version.CURRENT));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,9 @@ emp_no:integer | name:keyword
;

// Note: no matches in MV returned
in#[skip:-8.11.99, reason:Lucene multivalue warning introduced in 8.12 only]
in
required_feature: esql.mv_load

from employees | where job_positions in ("Internship", first_name) | keep emp_no, job_positions;
ignoreOrder:true
warning:Line 1:24: evaluation of [job_positions in (\"Internship\", first_name)] failed, treating result as null. Only first 20 failures recorded.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@
import java.util.Map;

public class EsqlFeatures implements FeatureSpecification {
private static final NodeFeature MV_LOAD = new NodeFeature("esql.mv_load");

@Override
public Map<NodeFeature, Version> getHistoricalFeatures() {
return Map.of(TransportEsqlStatsAction.ESQL_STATS_FEATURE, Version.V_8_11_0);
return Map.ofEntries(
Map.entry(TransportEsqlStatsAction.ESQL_STATS_FEATURE, Version.V_8_11_0),
Map.entry(MV_LOAD, Version.V_8_12_0)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ public CsvTests(String fileName, String groupName, String testName, Integer line

public final void test() throws Throwable {
try {
/*
* We're intentionally not NodeFeatures here because we expect all
* of the features to be supported in this unit test.
*/
assumeTrue("Test " + testName + " is not enabled", isEnabled(testName, Version.CURRENT));
doTest();
} catch (Throwable th) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public static class CsvSpecParser implements SpecReader.Parser {
private final StringBuilder earlySchema = new StringBuilder();
private final StringBuilder query = new StringBuilder();
private final StringBuilder data = new StringBuilder();
private final List<String> requiredFeatures = new ArrayList<>();
private CsvTestCase testCase;

private CsvSpecParser() {}
Expand All @@ -41,13 +42,17 @@ public Object parse(String line) {
if (line.startsWith(SCHEMA_PREFIX)) {
assertThat("Early schema already declared " + earlySchema, earlySchema.length(), is(0));
earlySchema.append(line.substring(SCHEMA_PREFIX.length()).trim());
} else if (line.toLowerCase(Locale.ROOT).startsWith("required_feature:")) {
requiredFeatures.add(line.substring("required_feature:".length()).trim());
} else {
if (line.endsWith(";")) {
// pick up the query
testCase = new CsvTestCase();
query.append(line.substring(0, line.length() - 1).trim());
testCase.query = query.toString();
testCase.earlySchema = earlySchema.toString();
testCase.requiredFeatures = List.copyOf(requiredFeatures);
requiredFeatures.clear();
earlySchema.setLength(0);
query.setLength(0);
}
Expand All @@ -61,9 +66,10 @@ public Object parse(String line) {
// read the results
else {
// read data
if (line.toLowerCase(Locale.ROOT).startsWith("warning:")) {
String lower = line.toLowerCase(Locale.ROOT);
if (lower.startsWith("warning:")) {
testCase.expectedWarnings.add(line.substring("warning:".length()).trim());
} else if (line.toLowerCase(Locale.ROOT).startsWith("ignoreorder:")) {
} else if (lower.startsWith("ignoreorder:")) {
testCase.ignoreOrder = Boolean.parseBoolean(line.substring("ignoreOrder:".length()).trim());
} else if (line.startsWith(";")) {
testCase.expectedResults = data.toString();
Expand All @@ -88,6 +94,7 @@ public static class CsvTestCase {
public String expectedResults;
private final List<String> expectedWarnings = new ArrayList<>();
public boolean ignoreOrder;
public List<String> requiredFeatures = List.of();

// The emulated-specific warnings must always trail the non-emulated ones, if these are present. Otherwise, the closing bracket
// would need to be changed to a less common sequence (like `]#` maybe).
Expand Down

0 comments on commit 146d13c

Please sign in to comment.