Cache all rest tests tasks so long as they don't use shared clusters (#48161)
This commit is contained in:
parent
4c6d56bef0
commit
befc44c145
|
@ -5,10 +5,9 @@ import org.gradle.api.tasks.Nested;
|
||||||
import org.gradle.api.tasks.testing.Test;
|
import org.gradle.api.tasks.testing.Test;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.HashSet;
|
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
|
* 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
|
* 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<>();
|
private Collection<ElasticsearchCluster> clusters = new HashSet<>();
|
||||||
|
|
||||||
public RestTestRunnerTask() {
|
public RestTestRunnerTask() {
|
||||||
super();
|
this.getOutputs().doNotCacheIf("Caching disabled for this task since it uses a cluster shared by other tasks",
|
||||||
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));
|
* 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
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue