Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion benchmarks/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ mainClassName = 'org.openjdk.jmh.Main'
assemble.enabled = false
archivesBaseName = 'elasticsearch-benchmarks'

test.enabled = false
unitTest.enabled = false

dependencies {
compile("org.elasticsearch:elasticsearch:${version}") {
Expand Down
4 changes: 1 addition & 3 deletions buildSrc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,7 @@ if (project != rootProject) {
jarHell.enabled = false
thirdPartyAudit.enabled = false

test {
include "**/*Tests.class"
exclude "**/*IT.class"
unitTest {
// The test task is configured to runtimeJava version, but build-tools doesn't support all of them, so test
// with compiler instead on the ones that are too old.
if (project.runtimeJavaVersion <= JavaVersion.VERSION_1_10) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,14 @@ import com.carrotsearch.ant.tasks.junit4.JUnit4
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.api.UnknownTaskException
import org.gradle.api.plugins.JavaBasePlugin
import org.gradle.api.tasks.TaskContainer
import org.gradle.api.tasks.TaskProvider
import org.gradle.api.tasks.testing.Test

class RandomizedTestingPlugin implements Plugin<Project> {

void apply(Project project) {
setupSeed(project)
replaceTestTask(project.tasks)
createUnitTestTask(project.tasks)
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
project.rootProject.getGradle().getTaskGraph().whenReady {
Task test = project.getTasks().findByName("test")
if (test != null && (test instanceof RandomizedTestingTask) == false) {
throw new IllegalStateException("Test task was not replaced in project ${project.path}. Found ${test.getClass()}")
}
}
}

/**
Expand Down Expand Up @@ -57,35 +41,15 @@ class RandomizedTestingPlugin implements Plugin<Project> {
}
}

static void replaceTestTask(TaskContainer tasks) {
// Gradle 4.8 introduced lazy tasks, thus we deal both with the `test` task as well as it's provider
// https://github.com/gradle/gradle/issues/5730#issuecomment-398822153
// since we can't be sure if the task was ever realized, we remove both the provider and the task
TaskProvider<Test> oldTestProvider
try {
oldTestProvider = tasks.named('test')
} catch (UnknownTaskException unused) {
// no test task, ok, user will use testing task on their own
return
static void createUnitTestTask(TaskContainer tasks) {
// only create a unitTest task if the `test` task exists as some project don't make use of it.
tasks.matching { it.name == "test" }.all {
// We don't want to run any tests with the Gradle test runner since we add our own randomized runner
it.enabled = false
RandomizedTestingTask unitTest = tasks.create('unitTest', RandomizedTestingTask)
unitTest.description = 'Runs unit tests with the randomized testing framework'
it.dependsOn unitTest
}
Test oldTestTask = oldTestProvider.get()

// we still have to use replace here despite the remove above because the task container knows about the provider
// by the same name
RandomizedTestingTask newTestTask = tasks.replace('test', RandomizedTestingTask)
newTestTask.configure{
group = JavaBasePlugin.VERIFICATION_GROUP
description = 'Runs unit tests with the randomized testing framework'
dependsOn oldTestTask.dependsOn, 'testClasses'
classpath = oldTestTask.classpath
testClassesDirs = oldTestTask.project.sourceSets.test.output.classesDirs
}

// hack so check task depends on custom test
Task checkTask = tasks.getByName('check')
checkTask.dependsOn.remove(oldTestProvider)
checkTask.dependsOn.remove(oldTestTask)
checkTask.dependsOn.add(newTestTask)
}

static void configureAnt(AntBuilder ant) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import org.gradle.api.artifacts.ProjectDependency
import org.gradle.api.artifacts.ResolvedArtifact
import org.gradle.api.artifacts.dsl.RepositoryHandler
import org.gradle.api.execution.TaskExecutionGraph
import org.gradle.api.plugins.JavaBasePlugin
import org.gradle.api.plugins.JavaPlugin
import org.gradle.api.publish.maven.MavenPublication
import org.gradle.api.publish.maven.plugins.MavenPublishPlugin
Expand Down Expand Up @@ -888,15 +889,22 @@ class BuildPlugin implements Plugin<Project> {
parallelism System.getProperty('tests.jvms', project.rootProject.ext.defaultParallel)
onNonEmptyWorkDirectory 'wipe'
leaveTemporary true
project.sourceSets.matching { it.name == "test" }.all { test ->
task.testClassesDirs = test.output.classesDirs
task.classpath = test.runtimeClasspath
}
group = JavaBasePlugin.VERIFICATION_GROUP
dependsOn 'testClasses'

// Make sure all test tasks are configured properly
if (name != "test") {
project.tasks.matching { it.name == "test"}.all { testTask ->
task.testClassesDirs = testTask.testClassesDirs
task.classpath = testTask.classpath
task.shouldRunAfter testTask
}
}
if (name == "unitTest") {
include("**/*Tests.class")
}

// TODO: why are we not passing maxmemory to junit4?
jvmArg '-Xmx' + System.getProperty('tests.heap.size', '512m')
Expand Down Expand Up @@ -986,8 +994,6 @@ class BuildPlugin implements Plugin<Project> {

exclude '**/*$*.class'

dependsOn(project.tasks.testClasses)

project.plugins.withType(ShadowPlugin).whenPluginAdded {
// Test against a shadow jar if we made one
classpath -= project.tasks.compileJava.outputs.files
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ public class RestIntegTestTask extends DefaultTask {
super.dependsOn(runner)
clusterInit = project.tasks.create(name: "${name}Cluster#init", dependsOn: project.testClasses)
runner.dependsOn(clusterInit)
runner.classpath = project.sourceSets.test.runtimeClasspath
runner.testClassesDirs = project.sourceSets.test.output.classesDirs
clusterConfig = project.extensions.create("${name}Cluster", ClusterConfiguration.class, project)

// override/add more for rest tests
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/testKit/elasticsearch.build/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ forbiddenApisTest.enabled = false
// requires dependency on testing fw
jarHell.enabled = false
// we don't have tests for now
test.enabled = false
unitTest.enabled = false

task hello {
doFirst {
Expand Down
2 changes: 1 addition & 1 deletion client/benchmark/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ archivesBaseName = 'client-benchmarks'
mainClassName = 'org.elasticsearch.client.benchmark.BenchmarkMain'

// never try to invoke tests on the benchmark project - there aren't any
test.enabled = false
unitTest.enabled = false

dependencies {
compile 'org.apache.commons:commons-math3:3.2'
Expand Down
2 changes: 1 addition & 1 deletion client/client-benchmark-noop-api-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ dependenciesInfo.enabled = false
compileJava.options.compilerArgs << "-Xlint:-cast,-deprecation,-rawtypes,-try,-unchecked"

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

//we aren't releasing this jar
thirdPartyAudit.enabled = false
test.enabled = false
unitTest.enabled = false
1 change: 0 additions & 1 deletion distribution/bwc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ bwcVersions.forPreviousUnreleased { VersionCollection.UnreleasedVersionInfo unre
apply plugin: 'distribution'
// Not published so no need to assemble
assemble.enabled = false
assemble.dependsOn.remove('buildBwcVersion')

File checkoutDir = file("${buildDir}/bwc/checkout-${bwcBranch}")

Expand Down
2 changes: 1 addition & 1 deletion distribution/tools/java-version-checker/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ forbiddenApisMain {
replaceSignatureFiles 'jdk-signatures'
}

test.enabled = false
unitTest.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 {
unitTest {
// TODO: find a way to add permissions for the tests in this module
systemProperty 'tests.security.manager', 'false'
}
Expand Down
2 changes: 1 addition & 1 deletion libs/cli/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ dependencies {
compile "org.elasticsearch:elasticsearch-core:${version}"
}

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

Expand Down
2 changes: 1 addition & 1 deletion libs/plugin-classloader/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

test.enabled = false
unitTest.enabled = false

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

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

Expand Down
2 changes: 1 addition & 1 deletion modules/lang-painless/spi/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ dependencies {
}

// no tests...yet?
test.enabled = false
unitTest.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 {
unitTest {
/*
* 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 {
unitTest {
/*
* 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 @@ -64,7 +64,7 @@ task writeTestJavaPolicy {
}
}

test {
unitTest {
dependsOn writeTestJavaPolicy
// 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 @@ -31,7 +31,7 @@ check {
dependsOn 'qa:gce:check'
}

test {
unitTest {
// this is needed for insecure plugins, remove if possible!
systemProperty 'tests.artifact', project.name
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/examples/custom-suggester/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ integTestCluster {
}

// this plugin has no unit tests, only rest tests
tasks.test.enabled = false
tasks.unitTest.enabled = false
2 changes: 1 addition & 1 deletion plugins/examples/painless-whitelist/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ if (System.getProperty('tests.distribution') == null) {
integTestCluster.distribution = 'oss-zip'
}

test.enabled = false
unitTest.enabled = false
2 changes: 1 addition & 1 deletion plugins/examples/rest-handler/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ esplugin {
}

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

task exampleFixture(type: org.elasticsearch.gradle.test.AntFixture) {
dependsOn testClasses
Expand Down
2 changes: 1 addition & 1 deletion plugins/examples/script-expert-scoring/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ esplugin {
noticeFile rootProject.file('NOTICE.txt')
}

test.enabled = false
unitTest.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 @@ -76,7 +76,7 @@ task testRepositoryCreds(type: RandomizedTestingTask) {
}
project.check.dependsOn(testRepositoryCreds)

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

test.enabled = false
unitTest.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 {
unitTest {
systemProperty 'tests.security.manager', 'false'
}

Expand Down
2 changes: 1 addition & 1 deletion qa/full-cluster-restart/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ for (Version version : bwcVersions.indexCompatible) {
}
}

test.enabled = false // no unit tests for rolling upgrades, only the rest integration test
unitTest.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 {
Expand Down
2 changes: 1 addition & 1 deletion qa/mixed-cluster/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ for (Version version : bwcVersions.wireCompatible) {
}
}

test.enabled = false // no unit tests for rolling upgrades, only the rest integration test
unitTest.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 {
Expand Down
2 changes: 1 addition & 1 deletion qa/multi-cluster-search/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@ task integTest {
dependsOn = [mixedClusterTest]
}

test.enabled = false // no unit tests for multi-cluster-search, only the rest integration test
unitTest.enabled = false // no unit tests for multi-cluster-search, only the rest integration test

check.dependsOn(integTest)
2 changes: 1 addition & 1 deletion qa/rolling-upgrade/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ for (Version version : bwcVersions.wireCompatible) {
}
}

test.enabled = false // no unit tests for rolling upgrades, only the rest integration test
unitTest.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 {
Expand Down
2 changes: 1 addition & 1 deletion qa/vagrant/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ forbiddenApisMain {
}

// we don't have additional tests for the tests themselves
tasks.test.enabled = false
tasks.unitTest.enabled = false

// this project doesn't get published
tasks.dependencyLicenses.enabled = false
Expand Down
2 changes: 1 addition & 1 deletion qa/verify-version-constants/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ for (Version version : bwcVersions.indexCompatible) {
bwcTest.dependsOn(versionBwcTest)
}

test.enabled = false
unitTest.enabled = false

task integTest {
if (project.bwc_tests_enabled) {
Expand Down
2 changes: 1 addition & 1 deletion qa/wildfly/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ if (!Os.isFamily(Os.FAMILY_WINDOWS)) {

check.dependsOn(integTest)

test.enabled = false
unitTest.enabled = false

dependencyLicenses.enabled = false
dependenciesInfo.enabled = false
Expand Down
2 changes: 1 addition & 1 deletion rest-api-spec/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ apply plugin: 'elasticsearch.build'
apply plugin: 'nebula.maven-base-publish'
apply plugin: 'nebula.maven-scm'

test.enabled = false
unitTest.enabled = false
jarHell.enabled = false
Loading