فهرست منبع

Ensure that rest compatibility test task classpath is setup correctly (#69306)

Mark Vieira 4 سال پیش
والد
کامیت
2b5a103591

+ 2 - 1
buildSrc/src/main/java/org/elasticsearch/gradle/internal/rest/compat/RestCompatTestTransformTask.java

@@ -148,6 +148,7 @@ public class RestCompatTestTransformTask extends DefaultTask {
     @TaskAction
     public void transform() throws IOException {
         RestTestTransformer transformer = new RestTestTransformer();
+        // TODO: instead of flattening the FileTree here leverage FileTree.visit() so we can preserve folder hierarchy in a more robust way
         for (File file : getTestFiles().getFiles()) {
             YAMLParser yamlParser = YAML_FACTORY.createParser(file);
             List<ObjectNode> tests = READER.<ObjectNode>readValues(yamlParser).readAll();
@@ -157,7 +158,7 @@ public class RestCompatTestTransformTask extends DefaultTask {
             if (testFileParts.length != 2) {
                 throw new IllegalArgumentException("could not split " + file + " into expected parts");
             }
-            File output = new File(outputDirectory.get().getAsFile(), testFileParts[1]);
+            File output = new File(outputDirectory.get().dir(REST_TEST_PREFIX).getAsFile(), testFileParts[1]);
             output.getParentFile().mkdirs();
             try (SequenceWriter sequenceWriter = WRITER.writeValues(output)) {
                 for (ObjectNode transformedTest : transformRestTests) {

+ 18 - 11
buildSrc/src/main/java/org/elasticsearch/gradle/internal/rest/compat/YamlRestCompatTestPlugin.java

@@ -28,6 +28,7 @@ import org.gradle.api.Project;
 import org.gradle.api.Task;
 import org.gradle.api.artifacts.Configuration;
 import org.gradle.api.artifacts.Dependency;
+import org.gradle.api.file.Directory;
 import org.gradle.api.plugins.JavaBasePlugin;
 import org.gradle.api.provider.Provider;
 import org.gradle.api.tasks.SourceSet;
@@ -155,12 +156,7 @@ public class YamlRestCompatTestPlugin implements Plugin<Project> {
             .register("transformV" + compatibleVersion + "RestTests", RestCompatTestTransformTask.class, task -> {
                 task.getSourceDirectory().set(copyCompatYamlTestTask.flatMap(CopyRestTestsTask::getOutputResourceDir));
                 task.getOutputDirectory()
-                    .set(
-                        project.getLayout()
-                            .getBuildDirectory()
-                            .dir(compatTestsDir.resolve("transformed").resolve(RELATIVE_TEST_PATH).toString())
-                    );
-
+                    .set(project.getLayout().getBuildDirectory().dir(compatTestsDir.resolve("transformed").toString()));
                 task.onlyIf(t -> isEnabled(project));
             });
 
@@ -168,18 +164,29 @@ public class YamlRestCompatTestPlugin implements Plugin<Project> {
         yamlCompatTestSourceSet.getOutput().dir(copyCompatYamlSpecTask.map(CopyRestApiTask::getOutputResourceDir));
         yamlCompatTestSourceSet.getOutput().dir(transformCompatTestTask.map(RestCompatTestTransformTask::getOutputDirectory));
 
+        // Grab the original rest resources locations so we can omit them from the compatibility testing classpath down below
+        Provider<Directory> originalYamlSpecsDir = project.getTasks()
+            .withType(CopyRestApiTask.class)
+            .named(RestResourcesPlugin.COPY_REST_API_SPECS_TASK)
+            .flatMap(CopyRestApiTask::getOutputResourceDir);
+        Provider<Directory> originalYamlTestsDir = project.getTasks()
+            .withType(CopyRestTestsTask.class)
+            .named(RestResourcesPlugin.COPY_YAML_TESTS_TASK)
+            .flatMap(CopyRestTestsTask::getOutputResourceDir);
+
         // setup the yamlRestTest task
         Provider<RestIntegTestTask> yamlRestCompatTestTask = RestTestUtil.registerTask(project, yamlCompatTestSourceSet);
         project.getTasks().withType(RestIntegTestTask.class).named(SOURCE_SET_NAME).configure(testTask -> {
             // Use test runner and classpath from "normal" yaml source set
-            testTask.setTestClassesDirs(yamlTestSourceSet.getOutput().getClassesDirs());
+            testTask.setTestClassesDirs(
+                yamlTestSourceSet.getOutput().getClassesDirs().plus(yamlCompatTestSourceSet.getOutput().getClassesDirs())
+            );
             testTask.setClasspath(
-                yamlTestSourceSet.getRuntimeClasspath()
+                yamlCompatTestSourceSet.getRuntimeClasspath()
                     // remove the "normal" api and tests
                     .minus(project.files(yamlTestSourceSet.getOutput().getResourcesDir()))
-                    // add any additional classes/resources from the compatible source set
-                    // the api and tests are copied to the compatible source set
-                    .plus(yamlCompatTestSourceSet.getRuntimeClasspath())
+                    .minus(project.files(originalYamlSpecsDir))
+                    .minus(project.files(originalYamlTestsDir))
             );
             // run compatibility tests after "normal" tests
             testTask.mustRunAfter(project.getTasks().named(YamlRestTestPlugin.SOURCE_SET_NAME));

+ 2 - 2
buildSrc/src/main/java/org/elasticsearch/gradle/test/rest/YamlRestTestPlugin.java

@@ -74,7 +74,7 @@ public class YamlRestTestPlugin implements Plugin<Project> {
                 project.getTasks()
                     .withType(CopyRestApiTask.class)
                     .named(RestResourcesPlugin.COPY_REST_API_SPECS_TASK)
-                    .map(CopyRestApiTask::getOutputResourceDir)
+                    .flatMap(CopyRestApiTask::getOutputResourceDir)
             );
 
         yamlTestSourceSet.getOutput()
@@ -82,7 +82,7 @@ public class YamlRestTestPlugin implements Plugin<Project> {
                 project.getTasks()
                     .withType(CopyRestTestsTask.class)
                     .named(RestResourcesPlugin.COPY_YAML_TESTS_TASK)
-                    .map(CopyRestTestsTask::getOutputResourceDir)
+                    .flatMap(CopyRestTestsTask::getOutputResourceDir)
             );
 
         // setup IDE

+ 0 - 4
modules/reindex/build.gradle

@@ -162,10 +162,6 @@ if (Os.isFamily(Os.FAMILY_WINDOWS)) {
 }
 
 tasks.named("yamlRestCompatTest").configure {
-  onlyIf {
-    // These are broken right now so mute
-    false
-  }
   systemProperty 'tests.rest.blacklist', [
     'reindex/20_validation/reindex without source gives useful error message', /* type in exception message */
     'reindex/85_scripting/Reindex all docs with one doc deletion', /*type in a request*/