Skip to content

Commit 493761c

Browse files
authored
Cache all rest tests tasks so long as they don't use shared clusters (#48161)
1 parent 0907111 commit 493761c

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

buildSrc/src/main/java/org/elasticsearch/gradle/testclusters/RestTestRunnerTask.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@
55
import org.gradle.api.tasks.testing.Test;
66

77
import java.util.Collection;
8+
import java.util.Collections;
89
import java.util.HashSet;
910

10-
import static org.elasticsearch.gradle.testclusters.TestDistribution.INTEG_TEST;
11-
1211
/**
1312
* Customized version of Gradle {@link Test} task which tracks a collection of {@link ElasticsearchCluster} as a task input. We must do this
1413
* 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 {
2019
private Collection<ElasticsearchCluster> clusters = new HashSet<>();
2120

2221
public RestTestRunnerTask() {
23-
super();
24-
this.getOutputs().doNotCacheIf("Build cache is only enabled for tests against clusters using the 'integ-test' distribution",
25-
task -> clusters.stream().flatMap(c -> c.getNodes().stream()).anyMatch(n -> n.getTestDistribution() != INTEG_TEST));
22+
this.getOutputs().doNotCacheIf("Caching disabled for this task since it uses a cluster shared by other tasks",
23+
/*
24+
* Look for any other tasks which use the same cluster as this task. Since tests often have side effects for the cluster they
25+
* execute against, this state can cause issues when trying to cache tests results of tasks that share a cluster. To avoid any
26+
* undesired behavior we simply disable the cache if we detect that this task uses a cluster shared between multiple tasks.
27+
*/
28+
t -> getProject().getTasks().withType(RestTestRunnerTask.class)
29+
.stream()
30+
.filter(task -> task != this)
31+
.anyMatch(task -> Collections.disjoint(task.getClusters(), getClusters()) == false)
32+
);
2633
}
2734

2835
@Override

0 commit comments

Comments
 (0)