Jake Landis 8d311297ca
[7.x] Smarter copying of the rest specs and tests (#52114) (#52798)
* Smarter copying of the rest specs and tests (#52114)

This PR addresses the unnecessary copying of the rest specs and allows
for better semantics for which specs and tests are copied. By default
the rest specs will get copied if the project applies
`elasticsearch.standalone-rest-test` or `esplugin` and the project
has rest tests or you configure the custom extension `restResources`.

This PR also removes the need for dozens of places where the x-pack
specs were copied by supporting copying of the x-pack rest specs too.

The plugin/task introduced here can also copy the rest tests to the
local project through a similar configuration.

The new plugin/task allows a user to minimize the surface area of
which rest specs are copied. Per project can be configured to include
only a subset of the specs (or tests). Configuring a project to only
copy the specs when actually needed should help with build cache hit
rates since we can better define what is actually in use.
However, project level optimizations for build cache hit rates are
not included with this PR.

Also, with this PR you can no longer use the includePackaged flag on
integTest task.

The following items are included in this PR:
* new plugin: `elasticsearch.rest-resources`
* new tasks: CopyRestApiTask and CopyRestTestsTask - performs the copy
* new extension 'restResources'
```
restResources {
  restApi {
    includeCore 'foo' , 'bar' //will include the core specs that start with foo and bar
    includeXpack 'baz' //will include x-pack specs that start with baz
  }
  restTests {
    includeCore 'foo', 'bar' //will include the core tests that start with foo and bar
    includeXpack 'baz' //will include the x-pack tests that start with baz
  }
}

```
2020-02-26 08:13:41 -06:00

116 lines
4.1 KiB
Groovy

import org.elasticsearch.gradle.Version
import org.elasticsearch.gradle.testclusters.RestTestRunnerTask
apply plugin: 'elasticsearch.testclusters'
apply plugin: 'elasticsearch.standalone-test'
dependencies {
testCompile project(':x-pack:qa')
}
tasks.register("bwcTest") {
description = 'Runs backwards compatibility tests.'
group = 'verification'
}
for (Version bwcVersion : bwcVersions.wireCompatible) {
String baseName = "v${bwcVersion}"
testClusters {
"${baseName}-leader" {
numberOfNodes = 3
}
"${baseName}-follower" {
numberOfNodes = 3
}
}
testClusters.matching { it.name.startsWith(baseName) }.all {
testDistribution = "DEFAULT"
versions = [bwcVersion.toString(), project.version]
setting 'repositories.url.allowed_urls', 'http://snapshot.test*'
setting 'xpack.security.enabled', 'false'
setting 'xpack.monitoring.enabled', 'false'
setting 'xpack.ml.enabled', 'false'
setting 'xpack.watcher.enabled', 'false'
setting 'xpack.license.self_generated.type', 'trial'
}
tasks.withType(RestTestRunnerTask).matching { it.name.startsWith(baseName) }.configureEach {
useCluster testClusters."${baseName}-leader"
useCluster testClusters."${baseName}-follower"
systemProperty 'tests.upgrade_from_version', bwcVersion.toString().replace('-SNAPSHOT', '')
doFirst {
if (name.endsWith("#clusterTest") == false) {
println "Upgrade node $it"
testClusters."${baseName}-${kindExt}".nextNodeToNextVersion()
}
nonInputProperties.systemProperty('tests.rest.cluster', "${-> testClusters."${baseName}-${kindExt}".allHttpSocketURI.join(",")}")
nonInputProperties.systemProperty('tests.clustername', "${-> testClusters."${baseName}-${kindExt}".getName()}")
nonInputProperties.systemProperty('tests.leader_host', "${-> testClusters."${baseName}-leader".allHttpSocketURI.last()}")
nonInputProperties.systemProperty('tests.leader_remote_cluster_seed', "${-> testClusters."${baseName}-leader".allTransportPortURI.last()}")
nonInputProperties.systemProperty('tests.follower_host', "${-> testClusters."${baseName}-follower".allHttpSocketURI.last()}")
nonInputProperties.systemProperty('tests.follower_remote_cluster_seed', "${-> testClusters."${baseName}-follower".allTransportPortURI.last()}")
}
}
for (kind in ["follower", "leader"]) {
// Attention!! Groovy trap: do not pass `kind` to a closure
tasks.register("${baseName}#${kind}#clusterTest", RestTestRunnerTask) {
systemProperty 'tests.rest.upgrade_state', 'none'
systemProperty 'tests.rest.cluster_name', kind
ext.kindExt = kind
}
tasks.register("${baseName}#${kind}#oneThirdUpgradedTest", RestTestRunnerTask) {
systemProperty 'tests.rest.upgrade_state', 'one_third'
systemProperty 'tests.rest.cluster_name', kind
dependsOn "${baseName}#leader#clusterTest", "${baseName}#follower#clusterTest"
ext.kindExt = kind
}
tasks.register("${baseName}#${kind}#twoThirdsUpgradedTest", RestTestRunnerTask) {
systemProperty 'tests.rest.upgrade_state', 'two_third'
systemProperty 'tests.rest.cluster_name', kind
dependsOn "${baseName}#${kind}#oneThirdUpgradedTest"
ext.kindExt = kind
}
tasks.register("${baseName}#${kind}#upgradedClusterTest", RestTestRunnerTask) {
systemProperty 'tests.rest.upgrade_state', 'all'
systemProperty 'tests.rest.cluster_name', kind
dependsOn "${baseName}#${kind}#twoThirdsUpgradedTest"
ext.kindExt = kind
}
}
tasks.named("${baseName}#follower#clusterTest") {
dependsOn "${baseName}#leader#clusterTest"
}
tasks.named("${baseName}#leader#oneThirdUpgradedTest") {
dependsOn "${baseName}#follower#upgradedClusterTest"
}
tasks.register("${baseName}#bwcTest") {
dependsOn "${baseName}#leader#upgradedClusterTest"
}
if (project.bwc_tests_enabled) {
bwcTest.dependsOn("${baseName}#bwcTest")
}
}
task bwcTestSnapshots {
if (project.bwc_tests_enabled) {
for (final def version : bwcVersions.unreleasedWireCompatible) {
dependsOn "v${version}#bwcTest"
}
}
}
check.dependsOn(bwcTestSnapshots)
test.enabled = false