Skip to content

Commit

Permalink
ESQL: Skip function signature test sometimes
Browse files Browse the repository at this point in the history
This skips the function signature test when we are running a subset of
the tests. That's important because it'll fail spuriously in that case.

Closes elastic#101527
  • Loading branch information
nik9000 committed Nov 2, 2023
1 parent df9002a commit baf1780
Showing 1 changed file with 33 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@
import org.junit.After;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;

import java.io.IOException;
import java.nio.file.Files;
Expand Down Expand Up @@ -117,11 +121,11 @@ public static Literal randomLiteral(DataType type) {

protected TestCaseSupplier.TestCase testCase;

protected static Iterable<Object[]> parameterSuppliersFromTypedData(List<TestCaseSupplier> cases) {
protected static Iterable<Object[]> parameterSuppliersFromTypedData(List<TestCaseSupplier> suppliers) {
// TODO rename this method to something more descriptive. Javadoc. And make sure all parameters are "representable" types.
List<Object[]> parameters = new ArrayList<>(cases.size());
for (TestCaseSupplier element : cases) {
parameters.add(new Object[] { element });
List<Object[]> parameters = new ArrayList<>(suppliers.size());
for (TestCaseSupplier supplier : suppliers) {
parameters.add(new Object[] { supplier });
}
return parameters;
}
Expand Down Expand Up @@ -494,13 +498,34 @@ public void testSerializationOfSimple() {
assertSerialization(buildFieldExpression(testCase));
}

private static boolean ranAllTests = false;

@ClassRule
public static TestRule rule = new TestRule() {
@Override
public Statement apply(Statement base, Description description) {
for (Description d : description.getChildren()) {
if (d.getChildren().size() > 1) {
ranAllTests = true;
return base;
}
}
return base;
}
};

@AfterClass
public static void testFunctionInfo() {
if (ranAllTests == false) {
LogManager.getLogger(getTestClass()).info("Skipping function info checks because we're running a portion of the tests");
return;
}
FunctionDefinition definition = definition();
if (definition == null) {
LogManager.getLogger(getTestClass()).info("Skipping function info checks because the function isn't registered");
return;
}
LogManager.getLogger(getTestClass()).info("Running function info checks");
EsqlFunctionRegistry.FunctionDescription description = EsqlFunctionRegistry.description(definition);
List<EsqlFunctionRegistry.ArgSignature> args = description.args();

Expand Down Expand Up @@ -763,6 +788,10 @@ public static void renderSignature() throws IOException {
if (System.getProperty("generateDocs") == null) {
return;
}
if (ranAllTests == false) {
LogManager.getLogger(getTestClass()).info("Skipping rendering signature because we're running a portion of the tests");
return;
}
FunctionDefinition definition = definition();
if (definition == null) {
LogManager.getLogger(getTestClass()).info("Skipping rendering signature because the function isn't registered");
Expand Down

0 comments on commit baf1780

Please sign in to comment.