Skip to content

Commit f1ebaf7

Browse files
committed
No longer replace test task, create implicit instead
Closes #31324. The issue has full context in comments. With this change the `test` task becomes nothing more than an alias for `utest`. Some of the stand alone tests that had a `test` task now have `integTest`, and a few of them that used to have `integTest` to run multiple tests now only have `check`. This will also help separarate unit/micro tests from integration tests.
1 parent 9e464d8 commit f1ebaf7

File tree

57 files changed

+110
-235
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+110
-235
lines changed

benchmarks/build.gradle

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ build.dependsOn.remove('assemble')
4141

4242
archivesBaseName = 'elasticsearch-benchmarks'
4343

44-
test.enabled = false
45-
4644
dependencies {
4745
compile("org.elasticsearch:elasticsearch:${version}") {
4846
// JMH ships with the conflicting version 4.6. This prevents us from using jopt-simple in benchmarks (which should be ok) but allows

buildSrc/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ if (project != rootProject) {
146146
thirdPartyAudit.enabled = false
147147

148148
// test for elasticsearch.build tries to run with ES...
149-
test.enabled = false
149+
utest.enabled = false
150150

151151
// TODO: re-enable once randomizedtesting gradle code is published and removed from here
152152
licenseHeaders.enabled = false

buildSrc/src/main/groovy/com/carrotsearch/gradle/junit4/RandomizedTestingPlugin.groovy

Lines changed: 25 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,19 @@ package com.carrotsearch.gradle.junit4
22

33
import com.carrotsearch.ant.tasks.junit4.JUnit4
44
import org.gradle.api.AntBuilder
5-
import org.gradle.api.GradleException
65
import org.gradle.api.Plugin
76
import org.gradle.api.Project
8-
import org.gradle.api.Task
97
import org.gradle.api.plugins.JavaBasePlugin
10-
import org.gradle.api.tasks.TaskContainer
118
import org.gradle.api.tasks.testing.Test
129

1310
import java.util.concurrent.atomic.AtomicBoolean
1411

1512
class RandomizedTestingPlugin implements Plugin<Project> {
1613

17-
static private AtomicBoolean sanityCheckConfigured = new AtomicBoolean(false)
18-
1914
void apply(Project project) {
2015
setupSeed(project)
21-
replaceTestTask(project.tasks)
16+
createTestTask(project)
2217
configureAnt(project.ant)
23-
configureSanityCheck(project)
24-
}
25-
26-
private static void configureSanityCheck(Project project) {
27-
// Check the task graph to confirm tasks were indeed replaced
28-
// https://github.com/elastic/elasticsearch/issues/31324
29-
if (sanityCheckConfigured.getAndSet(true) == false) {
30-
project.rootProject.getGradle().getTaskGraph().whenReady {
31-
def nonConforming = project.getGradle().getTaskGraph().allTasks
32-
.findAll { it.name == "test" }
33-
.findAll { (it instanceof RandomizedTestingTask) == false}
34-
.collect { "${it.path} -> ${it.class}" }
35-
if (nonConforming.isEmpty() == false) {
36-
throw new GradleException("Found the ${nonConforming.size()} `test` tasks:" +
37-
"\n ${nonConforming.join("\n ")}")
38-
}
39-
}
40-
}
4118
}
4219

4320
/**
@@ -67,32 +44,40 @@ class RandomizedTestingPlugin implements Plugin<Project> {
6744
}
6845
}
6946

70-
static void replaceTestTask(TaskContainer tasks) {
71-
Test oldTestTask = tasks.findByPath('test')
72-
if (oldTestTask == null) {
73-
// no test task, ok, user will use testing task on their own
47+
static void createTestTask(Project project) {
48+
Test oldTestTask = project.tasks.findByPath('test')
49+
if (oldTestTask != null) {
50+
oldTestTask.enabled = false
51+
if (oldTestTask.getDependsOn().isEmpty() == false) {
52+
// we used to pass dependencies along to the new task,
53+
// we no longer do, so make sure nobody relies on that.
54+
throw new Exception("did not expect any dependencies for test task but got: ${oldTestTask.getDependsOn()}")
55+
}
56+
oldTestTask.dependsOn('utest')
57+
} else {
7458
return
7559
}
76-
tasks.remove(oldTestTask)
7760

78-
Map properties = [
79-
name: 'test',
61+
RandomizedTestingTask newTestTask = project.tasks.create([
62+
name: 'utest',
8063
type: RandomizedTestingTask,
81-
dependsOn: oldTestTask.dependsOn,
8264
group: JavaBasePlugin.VERIFICATION_GROUP,
8365
description: 'Runs unit tests with the randomized testing framework'
84-
]
85-
RandomizedTestingTask newTestTask = tasks.create(properties)
66+
])
8667
newTestTask.classpath = oldTestTask.classpath
8768
newTestTask.testClassesDir = oldTestTask.project.sourceSets.test.output.classesDir
88-
// since gradle 4.5, tasks immutable dependencies are "hidden" (do not show up in dependsOn)
89-
// so we must explicitly add a dependency on generating the test classpath
9069
newTestTask.dependsOn('testClasses')
9170

92-
// hack so check task depends on custom test
93-
Task checkTask = tasks.findByPath('check')
94-
checkTask.dependsOn.remove(oldTestTask)
95-
checkTask.dependsOn.add(newTestTask)
71+
project.tasks.findByPath('check').dependsOn.add(newTestTask)
72+
// if there isn't actually a tests folder disable the task. Since we still have IT and Test in mixed folders
73+
// need to check by file name convention
74+
Set<File> testSources = project.sourceSets.test.java.getFiles().findAll { it.name.endsWith("Tests.java") }
75+
if (testSources.isEmpty()) {
76+
newTestTask.enabled = false
77+
project.logger.info("Found ${testSources.size()} source files, utest task will be disabled")
78+
} else {
79+
project.logger.debug("Found ${testSources.size()} source files, utest task will be enabled")
80+
}
9681
}
9782

9883
static void configureAnt(AntBuilder ant) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@ class BuildPlugin implements Plugin<Project> {
742742

743743
/** Configures the test task */
744744
static Task configureTest(Project project) {
745-
RandomizedTestingTask test = project.tasks.getByName('test')
745+
RandomizedTestingTask test = project.tasks.getByName('utest')
746746
test.configure(commonTestConfig(project))
747747
test.configure {
748748
include '**/*Tests.class'
@@ -765,7 +765,7 @@ class BuildPlugin implements Plugin<Project> {
765765
private static configurePrecommit(Project project) {
766766
Task precommit = PrecommitTasks.create(project, true)
767767
project.check.dependsOn(precommit)
768-
project.test.mustRunAfter(precommit)
768+
project.utest.mustRunAfter(precommit)
769769
// only require dependency licenses for non-elasticsearch deps
770770
project.dependencyLicenses.dependencies = project.configurations.runtime.fileCollection {
771771
it.group.startsWith('org.elasticsearch') == false

buildSrc/src/main/groovy/org/elasticsearch/gradle/plugin/PluginBuildPlugin.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public class PluginBuildPlugin extends BuildPlugin {
110110
/** Adds an integTest task which runs rest tests */
111111
private static void createIntegTestTask(Project project) {
112112
RestIntegTestTask integTest = project.tasks.create('integTest', RestIntegTestTask.class)
113-
integTest.mustRunAfter(project.precommit, project.test)
113+
integTest.mustRunAfter(project.precommit, project.utest)
114114
project.integTestCluster.distribution = 'integ-test-zip'
115115
project.check.dependsOn(integTest)
116116
}

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

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Licensed to Elasticsearch under one or more contributor
3-
* license agreements. See the NOTICE file distributed with
3+
* license agreements. See the NOTICE file delasticsearch.standalone-testistributed with
44
* this work for additional information regarding copyright
55
* ownership. Elasticsearch licenses this file to you under
66
* the Apache License, Version 2.0 (the "License"); you may
@@ -36,26 +36,25 @@ public class StandaloneTestPlugin implements Plugin<Project> {
3636
public void apply(Project project) {
3737
project.pluginManager.apply(StandaloneRestTestPlugin)
3838

39-
Map testOptions = [
40-
name: 'test',
39+
BuildPlugin.configureCompile(project)
40+
project.tasks.withType(JavaCompile) {
41+
// This will be the default in Gradle 5.0
42+
if (options.compilerArgs.contains("-processor") == false) {
43+
options.compilerArgs << '-proc:none'
44+
}
45+
}
46+
47+
RandomizedTestingTask test = project.tasks.create([
48+
name: 'integTest',
4149
type: RandomizedTestingTask,
4250
dependsOn: 'testClasses',
4351
group: JavaBasePlugin.VERIFICATION_GROUP,
4452
description: 'Runs unit tests that are separate'
45-
]
46-
RandomizedTestingTask test = project.tasks.create(testOptions)
53+
])
4754
test.configure(BuildPlugin.commonTestConfig(project))
48-
BuildPlugin.configureCompile(project)
4955
test.classpath = project.sourceSets.test.runtimeClasspath
5056
test.testClassesDir project.sourceSets.test.output.classesDir
5157
test.mustRunAfter(project.precommit)
5258
project.check.dependsOn(test)
53-
54-
project.tasks.withType(JavaCompile) {
55-
// This will be the default in Gradle 5.0
56-
if (options.compilerArgs.contains("-processor") == false) {
57-
options.compilerArgs << '-proc:none'
58-
}
59-
}
6059
}
6160
}

client/benchmark/build.gradle

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,6 @@ build.dependsOn.remove('assemble')
4444
archivesBaseName = 'client-benchmarks'
4545
mainClassName = 'org.elasticsearch.client.benchmark.BenchmarkMain'
4646

47-
48-
// never try to invoke tests on the benchmark project - there aren't any
49-
check.dependsOn.remove(test)
50-
// explicitly override the test task too in case somebody invokes 'gradle test' so it won't trip
51-
task test(type: Test, overwrite: true)
52-
5347
dependencies {
5448
compile 'org.apache.commons:commons-math3:3.2'
5549

client/client-benchmark-noop-api-plugin/build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,4 @@ dependenciesInfo.enabled = false
3737
compileJava.options.compilerArgs << "-Xlint:-cast,-deprecation,-rawtypes,-try,-unchecked"
3838

3939
// no unit tests
40-
test.enabled = false
4140
integTest.enabled = false

client/test/build.gradle

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,4 @@ dependenciesInfo.enabled = false
5656
namingConventions.enabled = false
5757

5858
//we aren't releasing this jar
59-
thirdPartyAudit.enabled = false
60-
test.enabled = false
59+
thirdPartyAudit.enabled = false

distribution/tools/java-version-checker/build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ targetCompatibility = JavaVersion.VERSION_1_7
77
// java_version_checker do not depend on core so only JDK signatures should be checked
88
forbiddenApisMain.signaturesURLs = [PrecommitTasks.getResource('/forbidden/jdk-signatures.txt')]
99

10-
test.enabled = false
1110
namingConventions.enabled = false
1211
javadoc.enabled = false
1312
loggerUsageCheck.enabled = false

0 commit comments

Comments
 (0)