Cache all rest tests tasks so long as they don't use shared clusters (#48161)

This commit is contained in:
Mark Vieira 2019-10-17 07:30:05 -07:00
parent 4c6d56bef0
commit befc44c145
No known key found for this signature in database
GPG Key ID: CA947EF7E6D4B105
1 changed files with 12 additions and 5 deletions

View File

@ -5,10 +5,9 @@ import org.gradle.api.tasks.Nested;
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<ElasticsearchCluster> 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