Browse Source

Build: Change test task sanity check to be per project (#33544)

This commit changes the sanity check which ensures the test task was
properly replaced with randomized testing to have a per project check,
isntead of a global one. The previous global check assumed all test
tasks within the root project and below should be randomized testing,
but that is not the case for a multi project in which only one project
is an elasticsearch plugin. While the new check is not able to emit all
of the failed replacements in one error message, the efficacy of the
check remains.
Ryan Ernst 7 years ago
parent
commit
e686909768

+ 4 - 15
buildSrc/src/main/groovy/com/carrotsearch/gradle/junit4/RandomizedTestingPlugin.groovy

@@ -1,7 +1,6 @@
 package com.carrotsearch.gradle.junit4
 
 import com.carrotsearch.ant.tasks.junit4.JUnit4
-import org.gradle.api.GradleException
 import org.gradle.api.Plugin
 import org.gradle.api.Project
 import org.gradle.api.Task
@@ -11,12 +10,8 @@ import org.gradle.api.tasks.TaskContainer
 import org.gradle.api.tasks.TaskProvider
 import org.gradle.api.tasks.testing.Test
 
-import java.util.concurrent.atomic.AtomicBoolean
-
 class RandomizedTestingPlugin implements Plugin<Project> {
 
-    static private AtomicBoolean sanityCheckConfigured = new AtomicBoolean(false)
-
     void apply(Project project) {
         setupSeed(project)
         replaceTestTask(project.tasks)
@@ -27,16 +22,10 @@ class RandomizedTestingPlugin implements Plugin<Project> {
     private static void configureSanityCheck(Project project) {
         // Check the task graph to confirm tasks were indeed replaced
         // https://github.com/elastic/elasticsearch/issues/31324
-        if (sanityCheckConfigured.getAndSet(true) == false) {
-            project.rootProject.getGradle().getTaskGraph().whenReady {
-                List<Task> nonConforming = project.getGradle().getTaskGraph().allTasks
-                        .findAll { it.name == "test" }
-                        .findAll { (it instanceof RandomizedTestingTask) == false}
-                        .collect { "${it.path} -> ${it.class}" }
-                if (nonConforming.isEmpty() == false) {
-                    throw new GradleException("Found the ${nonConforming.size()} `test` tasks:" +
-                            "\n  ${nonConforming.join("\n  ")}")
-                }
+        project.rootProject.getGradle().getTaskGraph().whenReady {
+            Task test = project.getTasks().findByName("test")
+            if (test != null && (test instanceof RandomizedTestingTask) == false) {
+                throw new IllegalStateException("Test task was not replaced in project ${project.path}. Found ${test.getClass()}")
             }
         }
     }