From 154ea3cf8e1c2e305fc9d6211b6f36a666c4063b Mon Sep 17 00:00:00 2001 From: Mark Vieira Date: Wed, 16 Oct 2019 13:20:06 -0700 Subject: [PATCH] Cache all rest tests tasks so long as they don't use shared clusters Signed-off-by: Mark Vieira --- .../gradle/testclusters/RestTestRunnerTask.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/buildSrc/src/main/java/org/elasticsearch/gradle/testclusters/RestTestRunnerTask.java b/buildSrc/src/main/java/org/elasticsearch/gradle/testclusters/RestTestRunnerTask.java index 833ce019d1ddc..9698e4a664b74 100644 --- a/buildSrc/src/main/java/org/elasticsearch/gradle/testclusters/RestTestRunnerTask.java +++ b/buildSrc/src/main/java/org/elasticsearch/gradle/testclusters/RestTestRunnerTask.java @@ -5,10 +5,9 @@ import org.gradle.api.tasks.testing.Test; import java.util.Collection; +import java.util.Collections; import java.util.HashSet; -import static org.elasticsearch.gradle.testclusters.TestDistribution.INTEG_TEST; - /** * Customized version of Gradle {@link Test} task which tracks a collection of {@link ElasticsearchCluster} as a task input. We must do this * as a custom task type because the current {@link org.gradle.api.tasks.TaskInputs} runtime API does not have a way to register @@ -20,9 +19,17 @@ public class RestTestRunnerTask extends Test implements TestClustersAware { private Collection clusters = new HashSet<>(); public RestTestRunnerTask() { - super(); - this.getOutputs().doNotCacheIf("Build cache is only enabled for tests against clusters using the 'integ-test' distribution", - task -> clusters.stream().flatMap(c -> c.getNodes().stream()).anyMatch(n -> n.getTestDistribution() != INTEG_TEST)); + this.getOutputs().doNotCacheIf("Caching disabled for this task since it uses a cluster shared by other tasks", + /* + * Look for any other tasks which use the same cluster as this task. Since tests often have side effects for the cluster they + * execute against, this state can cause issues when trying to cache tests results of tasks that share a cluster. To avoid any + * undesired behavior we simply disable the cache if we detect that this task uses a cluster shared between multiple tasks. + */ + t -> getProject().getTasks().withType(RestTestRunnerTask.class) + .stream() + .filter(task -> task != this) + .anyMatch(task -> Collections.disjoint(task.getClusters(), getClusters()) == false) + ); } @Override