Skip to content

Commit

Permalink
No longer replace test task, create implicit instead
Browse files Browse the repository at this point in the history
Closes elastic#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.
  • Loading branch information
alpar-t committed Jun 22, 2018
1 parent 9eaa07e commit 6ccfec8
Show file tree
Hide file tree
Showing 57 changed files with 110 additions and 235 deletions.
2 changes: 0 additions & 2 deletions benchmarks/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ build.dependsOn.remove('assemble')

archivesBaseName = 'elasticsearch-benchmarks'

test.enabled = false

dependencies {
compile("org.elasticsearch:elasticsearch:${version}") {
// JMH ships with the conflicting version 4.6. This prevents us from using jopt-simple in benchmarks (which should be ok) but allows
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ if (project != rootProject) {
thirdPartyAudit.enabled = false

// test for elasticsearch.build tries to run with ES...
test.enabled = false
utest.enabled = false

// TODO: re-enable once randomizedtesting gradle code is published and removed from here
licenseHeaders.enabled = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,19 @@ package com.carrotsearch.gradle.junit4

import com.carrotsearch.ant.tasks.junit4.JUnit4
import org.gradle.api.AntBuilder
import org.gradle.api.GradleException
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.api.plugins.JavaBasePlugin
import org.gradle.api.tasks.TaskContainer
import org.gradle.api.tasks.testing.Test

import java.util.concurrent.atomic.AtomicBoolean

class RandomizedTestingPlugin implements Plugin<Project> {

static private AtomicBoolean sanityCheckConfigured = new AtomicBoolean(false)

void apply(Project project) {
setupSeed(project)
replaceTestTask(project.tasks)
createTestTask(project)
configureAnt(project.ant)
configureSanityCheck(project)
}

private static void configureSanityCheck(Project project) {
// Check the task graph to confirm tasks were indeed replaced
// https://github.com/elastic/elasticsearch/issues/31324
if (sanityCheckConfigured.getAndSet(true) == false) {
project.rootProject.getGradle().getTaskGraph().whenReady {
def nonConforming = project.getGradle().getTaskGraph().allTasks
.findAll { it.name == "test" }
.findAll { (it instanceof RandomizedTestingTask) == false}
.collect { "${it.path} -> ${it.class}" }
if (nonConforming.isEmpty() == false) {
throw new GradleException("Found the ${nonConforming.size()} `test` tasks:" +
"\n ${nonConforming.join("\n ")}")
}
}
}
}

/**
Expand Down Expand Up @@ -67,32 +44,40 @@ class RandomizedTestingPlugin implements Plugin<Project> {
}
}

static void replaceTestTask(TaskContainer tasks) {
Test oldTestTask = tasks.findByPath('test')
if (oldTestTask == null) {
// no test task, ok, user will use testing task on their own
static void createTestTask(Project project) {
Test oldTestTask = project.tasks.findByPath('test')
if (oldTestTask != null) {
oldTestTask.enabled = false
if (oldTestTask.getDependsOn().isEmpty() == false) {
// we used to pass dependencies along to the new task,
// we no longer do, so make sure nobody relies on that.
throw new Exception("did not expect any dependencies for test task but got: ${oldTestTask.getDependsOn()}")
}
oldTestTask.dependsOn('utest')
} else {
return
}
tasks.remove(oldTestTask)

Map properties = [
name: 'test',
RandomizedTestingTask newTestTask = project.tasks.create([
name: 'utest',
type: RandomizedTestingTask,
dependsOn: oldTestTask.dependsOn,
group: JavaBasePlugin.VERIFICATION_GROUP,
description: 'Runs unit tests with the randomized testing framework'
]
RandomizedTestingTask newTestTask = tasks.create(properties)
])
newTestTask.classpath = oldTestTask.classpath
newTestTask.testClassesDir = oldTestTask.project.sourceSets.test.output.classesDir
// since gradle 4.5, tasks immutable dependencies are "hidden" (do not show up in dependsOn)
// so we must explicitly add a dependency on generating the test classpath
newTestTask.dependsOn('testClasses')

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

static void configureAnt(AntBuilder ant) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ class BuildPlugin implements Plugin<Project> {

/** Configures the test task */
static Task configureTest(Project project) {
RandomizedTestingTask test = project.tasks.getByName('test')
RandomizedTestingTask test = project.tasks.getByName('utest')
test.configure(commonTestConfig(project))
test.configure {
include '**/*Tests.class'
Expand All @@ -765,7 +765,7 @@ class BuildPlugin implements Plugin<Project> {
private static configurePrecommit(Project project) {
Task precommit = PrecommitTasks.create(project, true)
project.check.dependsOn(precommit)
project.test.mustRunAfter(precommit)
project.utest.mustRunAfter(precommit)
// only require dependency licenses for non-elasticsearch deps
project.dependencyLicenses.dependencies = project.configurations.runtime.fileCollection {
it.group.startsWith('org.elasticsearch') == false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public class PluginBuildPlugin extends BuildPlugin {
/** Adds an integTest task which runs rest tests */
private static void createIntegTestTask(Project project) {
RestIntegTestTask integTest = project.tasks.create('integTest', RestIntegTestTask.class)
integTest.mustRunAfter(project.precommit, project.test)
integTest.mustRunAfter(project.precommit, project.utest)
project.integTestCluster.distribution = 'integ-test-zip'
project.check.dependsOn(integTest)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* license agreements. See the NOTICE file delasticsearch.standalone-testistributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
Expand Down Expand Up @@ -36,26 +36,25 @@ public class StandaloneTestPlugin implements Plugin<Project> {
public void apply(Project project) {
project.pluginManager.apply(StandaloneRestTestPlugin)

Map testOptions = [
name: 'test',
BuildPlugin.configureCompile(project)
project.tasks.withType(JavaCompile) {
// This will be the default in Gradle 5.0
if (options.compilerArgs.contains("-processor") == false) {
options.compilerArgs << '-proc:none'
}
}

RandomizedTestingTask test = project.tasks.create([
name: 'integTest',
type: RandomizedTestingTask,
dependsOn: 'testClasses',
group: JavaBasePlugin.VERIFICATION_GROUP,
description: 'Runs unit tests that are separate'
]
RandomizedTestingTask test = project.tasks.create(testOptions)
])
test.configure(BuildPlugin.commonTestConfig(project))
BuildPlugin.configureCompile(project)
test.classpath = project.sourceSets.test.runtimeClasspath
test.testClassesDir project.sourceSets.test.output.classesDir
test.mustRunAfter(project.precommit)
project.check.dependsOn(test)

project.tasks.withType(JavaCompile) {
// This will be the default in Gradle 5.0
if (options.compilerArgs.contains("-processor") == false) {
options.compilerArgs << '-proc:none'
}
}
}
}
6 changes: 0 additions & 6 deletions client/benchmark/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,6 @@ build.dependsOn.remove('assemble')
archivesBaseName = 'client-benchmarks'
mainClassName = 'org.elasticsearch.client.benchmark.BenchmarkMain'


// never try to invoke tests on the benchmark project - there aren't any
check.dependsOn.remove(test)
// explicitly override the test task too in case somebody invokes 'gradle test' so it won't trip
task test(type: Test, overwrite: true)

dependencies {
compile 'org.apache.commons:commons-math3:3.2'

Expand Down
1 change: 0 additions & 1 deletion client/client-benchmark-noop-api-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,4 @@ dependenciesInfo.enabled = false
compileJava.options.compilerArgs << "-Xlint:-cast,-deprecation,-rawtypes,-try,-unchecked"

// no unit tests
test.enabled = false
integTest.enabled = false
3 changes: 1 addition & 2 deletions client/test/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,4 @@ dependenciesInfo.enabled = false
namingConventions.enabled = false

//we aren't releasing this jar
thirdPartyAudit.enabled = false
test.enabled = false
thirdPartyAudit.enabled = false
1 change: 0 additions & 1 deletion distribution/tools/java-version-checker/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ targetCompatibility = JavaVersion.VERSION_1_7
// java_version_checker do not depend on core so only JDK signatures should be checked
forbiddenApisMain.signaturesURLs = [PrecommitTasks.getResource('/forbidden/jdk-signatures.txt')]

test.enabled = false
namingConventions.enabled = false
javadoc.enabled = false
loggerUsageCheck.enabled = false
Expand Down
2 changes: 1 addition & 1 deletion distribution/tools/plugin-cli/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ dependencyLicenses {
mapping from: /bc.*/, to: 'bouncycastle'
}

test {
utest {
// TODO: find a way to add permissions for the tests in this module
systemProperty 'tests.security.manager', 'false'
}
1 change: 0 additions & 1 deletion libs/cli/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ dependencies {
compile "org.elasticsearch:elasticsearch-core:${version}"
}

test.enabled = false
// Since CLI does not depend on :server, it cannot run the jarHell task
jarHell.enabled = false

Expand Down
2 changes: 0 additions & 2 deletions libs/plugin-classloader/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
* under the License.
*/

test.enabled = false

// test depend on ES core...
forbiddenApisMain.enabled = false
jarHell.enabled = false
2 changes: 1 addition & 1 deletion modules/lang-painless/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ dependencyLicenses {
mapping from: /asm-.*/, to: 'asm'
}

test {
utest {
jvmArg '-XX:-OmitStackTraceInFastThrow'
}

Expand Down
5 changes: 1 addition & 4 deletions modules/lang-painless/spi/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,4 @@ publishing {

dependencies {
compile "org.elasticsearch:elasticsearch:${version}"
}

// no tests...yet?
test.enabled = false
}
2 changes: 1 addition & 1 deletion modules/reindex/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ run {
setting 'reindex.remote.whitelist', '127.0.0.1:*'
}

test {
utest {
/*
* We have to disable setting the number of available processors as tests in the
* same JVM randomize processors and will step on each other if we allow them to
Expand Down
2 changes: 1 addition & 1 deletion modules/transport-netty4/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ dependencyLicenses {
mapping from: /netty-.*/, to: 'netty'
}

test {
utest {
/*
* We have to disable setting the number of available processors as tests in the same JVM randomize processors and will step on each
* other if we allow them to set the number of available processors as it's set-once in Netty.
Expand Down
2 changes: 1 addition & 1 deletion plugins/discovery-ec2/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ bundlePlugin {
}
}

test {
utest {
// this is needed for insecure plugins, remove if possible!
systemProperty 'tests.artifact', project.name
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/discovery-gce/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ dependencyLicenses {
mapping from: /google-.*/, to: 'google'
}

test {
utest {
// this is needed for insecure plugins, remove if possible!
systemProperty 'tests.artifact', project.name
}
Expand Down
4 changes: 1 addition & 3 deletions plugins/examples/painless-whitelist/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,4 @@ dependencies {

integTestCluster {
distribution = 'zip'
}

test.enabled = false
}
3 changes: 0 additions & 3 deletions plugins/examples/rest-handler/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ esplugin {
classname 'org.elasticsearch.example.resthandler.ExampleRestHandlerPlugin'
}

// No unit tests in this example
test.enabled = false

task exampleFixture(type: org.elasticsearch.gradle.test.AntFixture) {
dependsOn testClasses
env 'CLASSPATH', "${ -> project.sourceSets.test.runtimeClasspath.asPath }"
Expand Down
1 change: 0 additions & 1 deletion plugins/examples/script-expert-scoring/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,3 @@ esplugin {
classname 'org.elasticsearch.example.expertscript.ExpertScriptPlugin'
}

test.enabled = false
2 changes: 1 addition & 1 deletion plugins/repository-s3/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ additionalTest('testRepositoryCreds'){
systemProperty 'es.allow_insecure_settings', 'true'
}

test {
utest {
// these are tested explicitly in separate test tasks
exclude '**/*CredentialsTests.class'
}
Expand Down
2 changes: 0 additions & 2 deletions qa/die-with-dignity/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,4 @@ integTestRunner {
systemProperty 'runtime.java.home', "${project.runtimeJavaHome}"
}

test.enabled = false

check.dependsOn integTest
2 changes: 1 addition & 1 deletion qa/evil-tests/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ dependencies {

// TODO: give each evil test its own fresh JVM for more isolation.

test {
integTest {
systemProperty 'tests.security.manager', 'false'
}

Expand Down
13 changes: 3 additions & 10 deletions qa/full-cluster-restart/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,9 @@ for (Version version : bwcVersions.indexCompatible) {
}
}

test.enabled = false // no unit tests for rolling upgrades, only the rest integration test

// basic integ tests includes testing bwc against the most recent version
task integTest {
if (project.bwc_tests_enabled) {
for (final def version : bwcVersions.snapshotsIndexCompatible) {
dependsOn "v${version}#bwcTest"
}
}
if (project.bwc_tests_enabled) {
check.dependsOn(bwcTest)
}

check.dependsOn(integTest)


13 changes: 3 additions & 10 deletions qa/mixed-cluster/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,8 @@ for (Version version : bwcVersions.wireCompatible) {
}
}

test.enabled = false // no unit tests for rolling upgrades, only the rest integration test

// basic integ tests includes testing bwc against the most recent version
task integTest {
if (project.bwc_tests_enabled) {
for (final def version : bwcVersions.snapshotsWireCompatible) {
dependsOn "v${version}#bwcTest"
}
}
if (project.bwc_tests_enabled) {
check.dependsOn(bwcTest)
}

check.dependsOn(integTest)

Loading

0 comments on commit 6ccfec8

Please sign in to comment.