Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down