Skip to content

Commit 7e18294

Browse files
authored
Common test config 6.x (#34806)
* Auto configure all test tasks (#34666) With this change, we apply the common test config automatically to all newly created tasks instead of opting in specifically. For plugin authors using the plugin externally this means that the configuration will be applied to their RandomizedTestingTasks as well. The purpose of the task is to simplify setup and make it easier to change projects that use the `test` task but actually run integration tests to use a task called `integTest` for clarity, but also because we may want to configure and run them differently. E.x. using different levels of concurrency. * Convert tests using old method
1 parent 91f09a1 commit 7e18294

File tree

10 files changed

+22
-35
lines changed

10 files changed

+22
-35
lines changed

buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,14 @@ class BuildPlugin implements Plugin<Project> {
9999
configureSourcesJar(project)
100100
configurePomGeneration(project)
101101

102+
applyCommonTestConfig(project)
102103
configureTest(project)
103104
configurePrecommit(project)
104105
configureDependenciesInfo(project)
105106
}
106107

107108

109+
108110
/** Performs checks on the build environment and prints information about the build environment. */
109111
static void globalBuildInfo(Project project) {
110112
if (project.rootProject.ext.has('buildChecksDone') == false) {
@@ -776,9 +778,8 @@ class BuildPlugin implements Plugin<Project> {
776778
}
777779
}
778780

779-
/** Returns a closure of common configuration shared by unit and integration tests. */
780-
static Closure commonTestConfig(Project project) {
781-
return {
781+
static void applyCommonTestConfig(Project project) {
782+
project.tasks.withType(RandomizedTestingTask) {
782783
jvm "${project.runtimeJavaHome}/bin/java"
783784
parallelism System.getProperty('tests.jvms', 'auto')
784785
ifNoTests System.getProperty('tests.ifNoTests', 'fail')
@@ -875,6 +876,8 @@ class BuildPlugin implements Plugin<Project> {
875876

876877
exclude '**/*$*.class'
877878

879+
dependsOn(project.tasks.testClasses)
880+
878881
project.plugins.withType(ShadowPlugin).whenPluginAdded {
879882
// Test against a shadow jar if we made one
880883
classpath -= project.tasks.compileJava.outputs.files
@@ -886,23 +889,9 @@ class BuildPlugin implements Plugin<Project> {
886889

887890
/** Configures the test task */
888891
static Task configureTest(Project project) {
889-
RandomizedTestingTask test = project.tasks.getByName('test')
890-
test.configure(commonTestConfig(project))
891-
test.configure {
892+
project.tasks.getByName('test') {
892893
include '**/*Tests.class'
893894
}
894-
895-
// Add a method to create additional unit tests for a project, which will share the same
896-
// randomized testing setup, but by default run no tests.
897-
project.extensions.add('additionalTest', { String name, Closure config ->
898-
RandomizedTestingTask additionalTest = project.tasks.create(name, RandomizedTestingTask.class)
899-
additionalTest.classpath = test.classpath
900-
additionalTest.testClassesDirs = test.testClassesDirs
901-
additionalTest.configure(commonTestConfig(project))
902-
additionalTest.configure(config)
903-
additionalTest.dependsOn(project.tasks.testClasses)
904-
project.check.dependsOn(additionalTest)
905-
});
906895
}
907896

908897
private static configurePrecommit(Project project) {

buildSrc/src/main/groovy/org/elasticsearch/gradle/test/RestIntegTestTask.groovy

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,6 @@ public class RestIntegTestTask extends DefaultTask {
6464
runner.testClassesDirs = project.sourceSets.test.output.classesDirs
6565
clusterConfig = project.extensions.create("${name}Cluster", ClusterConfiguration.class, project)
6666

67-
// start with the common test configuration
68-
runner.configure(BuildPlugin.commonTestConfig(project))
6967
// override/add more for rest tests
7068
runner.parallelism = '1'
7169
runner.include('**/*IT.class')

buildSrc/src/main/groovy/org/elasticsearch/gradle/test/StandaloneRestTestPlugin.groovy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public class StandaloneRestTestPlugin implements Plugin<Project> {
5050
project.getTasks().create("buildResources", ExportElasticsearchBuildResourcesTask)
5151
BuildPlugin.globalBuildInfo(project)
5252
BuildPlugin.configureRepositories(project)
53+
BuildPlugin.applyCommonTestConfig(project)
5354

5455
// only setup tests to build
5556
project.sourceSets.create('test')

buildSrc/src/main/groovy/org/elasticsearch/gradle/test/StandaloneTestPlugin.groovy

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ public class StandaloneTestPlugin implements Plugin<Project> {
4343
description: 'Runs unit tests that are separate'
4444
]
4545
RandomizedTestingTask test = project.tasks.create(testOptions)
46-
test.configure(BuildPlugin.commonTestConfig(project))
4746
BuildPlugin.configureCompile(project)
4847
test.classpath = project.sourceSets.test.runtimeClasspath
4948
test.testClassesDirs = project.sourceSets.test.output.classesDirs

plugins/repository-s3/build.gradle

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import org.elasticsearch.gradle.MavenFilteringHack
44
import org.elasticsearch.gradle.test.AntFixture
55
import org.elasticsearch.gradle.test.ClusterConfiguration
66
import org.elasticsearch.gradle.test.RestIntegTestTask
7+
import com.carrotsearch.gradle.junit4.RandomizedTestingTask
78

89
import java.lang.reflect.Field
910

@@ -68,11 +69,14 @@ bundlePlugin {
6869
}
6970
}
7071

71-
additionalTest('testRepositoryCreds'){
72+
task testRepositoryCreds(type: RandomizedTestingTask) {
7273
include '**/RepositoryCredentialsTests.class'
7374
include '**/S3BlobStoreRepositoryTests.class'
7475
systemProperty 'es.allow_insecure_settings', 'true'
76+
classpath = tasks.test.classpath
77+
testClassesDirs = tasks.test.testClassesDirs
7578
}
79+
project.check.dependsOn(testRepositoryCreds)
7680

7781
test {
7882
// these are tested explicitly in separate test tasks

server/build.gradle

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@
1717
* under the License.
1818
*/
1919

20-
2120
import com.carrotsearch.gradle.junit4.RandomizedTestingTask
22-
import org.elasticsearch.gradle.BuildPlugin
2321

2422
apply plugin: 'elasticsearch.build'
2523
apply plugin: 'nebula.optional-base'
@@ -155,10 +153,14 @@ if (isEclipse) {
155153
compileJava.options.compilerArgs << "-Xlint:-cast,-deprecation,-rawtypes,-try,-unchecked"
156154
compileTestJava.options.compilerArgs << "-Xlint:-cast,-deprecation,-rawtypes,-try,-unchecked"
157155

158-
additionalTest('testScriptDocValuesMissingV7Behaviour') {
156+
task testScriptDocValuesMissingV7Behaviour(type: RandomizedTestingTask) {
159157
include '**/ScriptDocValuesMissingV7BehaviourTests.class'
160158
systemProperty 'es.scripting.exception_for_missing_value', 'true'
159+
classpath = tasks.test.classpath
160+
testClassesDirs = tasks.test.testClassesDirs
161161
}
162+
check.dependsOn(testScriptDocValuesMissingV7Behaviour)
163+
162164
test {
163165
// these are tested explicitly in separate test tasks
164166
exclude '**/*ScriptDocValuesMissingV7BehaviourTests.class'
@@ -331,7 +333,6 @@ if (isEclipse == false || project.path == ":server-tests") {
331333
group: JavaBasePlugin.VERIFICATION_GROUP,
332334
description: 'Multi-node tests',
333335
dependsOn: test.dependsOn) {
334-
configure(BuildPlugin.commonTestConfig(project))
335336
classpath = project.test.classpath
336337
testClassesDirs = project.test.testClassesDirs
337338
include '**/*IT.class'
@@ -340,11 +341,14 @@ if (isEclipse == false || project.path == ":server-tests") {
340341
integTest.mustRunAfter test
341342
}
342343
// TODO: remove these compatibility tests in 7.0
343-
additionalTest('testScriptedMetricAggParamsV6Compatibility') {
344+
task testScriptedMetricAggParamsV6Compatibility(type: RandomizedTestingTask) {
344345
include '**/ScriptedMetricAggregatorAggStateV6CompatTests.class'
345346
include '**/InternalScriptedMetricAggStateV6CompatTests.class'
346347
systemProperty 'es.aggregations.enable_scripted_metric_agg_param', 'true'
348+
classpath = tasks.test.classpath
349+
testClassesDirs = tasks.test.testClassesDirs
347350
}
351+
check.dependsOn(testScriptedMetricAggParamsV6Compatibility)
348352

349353
test {
350354
// these are tested explicitly in separate test tasks

x-pack/plugin/ccr/build.gradle

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import com.carrotsearch.gradle.junit4.RandomizedTestingTask
2-
import org.elasticsearch.gradle.BuildPlugin
32

43
evaluationDependsOn(xpackModule('core'))
54

@@ -25,7 +24,6 @@ task internalClusterTest(type: RandomizedTestingTask,
2524
group: JavaBasePlugin.VERIFICATION_GROUP,
2625
description: 'Java fantasy integration tests',
2726
dependsOn: test.dependsOn) {
28-
configure(BuildPlugin.commonTestConfig(project))
2927
classpath = project.test.classpath
3028
testClassesDirs = project.test.testClassesDirs
3129
include '**/*IT.class'

x-pack/plugin/ml/build.gradle

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import com.carrotsearch.gradle.junit4.RandomizedTestingTask
2-
import org.elasticsearch.gradle.BuildPlugin
32

43
evaluationDependsOn(xpackModule('core'))
54

@@ -99,7 +98,6 @@ task internalClusterTest(type: RandomizedTestingTask,
9998
group: JavaBasePlugin.VERIFICATION_GROUP,
10099
description: 'Multi-node tests',
101100
dependsOn: test.dependsOn) {
102-
configure(BuildPlugin.commonTestConfig(project))
103101
classpath = project.test.classpath
104102
testClassesDirs = project.test.testClassesDirs
105103
include '**/*IT.class'

x-pack/plugin/monitoring/build.gradle

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import com.carrotsearch.gradle.junit4.RandomizedTestingTask
2-
import org.elasticsearch.gradle.BuildPlugin
32

43
evaluationDependsOn(xpackModule('core'))
54

@@ -61,7 +60,6 @@ task internalClusterTest(type: RandomizedTestingTask,
6160
group: JavaBasePlugin.VERIFICATION_GROUP,
6261
description: 'Multi-node tests',
6362
dependsOn: test.dependsOn) {
64-
configure(BuildPlugin.commonTestConfig(project))
6563
classpath = project.test.classpath
6664
testClassesDirs = project.test.testClassesDirs
6765
include '**/*IT.class'

x-pack/plugin/upgrade/build.gradle

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import com.carrotsearch.gradle.junit4.RandomizedTestingTask
2-
import org.elasticsearch.gradle.BuildPlugin
32

43
evaluationDependsOn(xpackModule('core'))
54

@@ -35,7 +34,6 @@ task internalClusterTest(type: RandomizedTestingTask,
3534
group: JavaBasePlugin.VERIFICATION_GROUP,
3635
description: 'Multi-node tests',
3736
dependsOn: test.dependsOn) {
38-
configure(BuildPlugin.commonTestConfig(project))
3937
classpath = project.test.classpath
4038
testClassesDirs = project.test.testClassesDirs
4139
include '**/*IT.class'

0 commit comments

Comments
 (0)