Skip to content

Commit

Permalink
Revert "Replace usages RandomizedTestingTask with built-in Gradle Test (
Browse files Browse the repository at this point in the history
elastic#40564)"

This reverts commit 2b2a3f5
  • Loading branch information
mark-vieira authored and Gurkan Kaymak committed May 27, 2019
1 parent 96adb04 commit 9a1fd06
Show file tree
Hide file tree
Showing 97 changed files with 1,552 additions and 666 deletions.
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
15 changes: 11 additions & 4 deletions buildSrc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -199,21 +199,24 @@ if (project != rootProject) {
into localDownloads
}

test {
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) {
executable = "${project.compilerJavaHome}/bin/java"
jvm = "${project.compilerJavaHome}/bin/java"
}
}


// This can't be an RandomizedTestingTask because we can't yet reference it
task integTest(type: Test) {
// integration test requires the local testing repo for example plugin builds
dependsOn project.rootProject.allprojects.collect {
it.tasks.matching { it.name == 'publishNebulaPublicationToLocalTestRepository'}
}
dependsOn setupLocalDownloads
exclude "**/*Tests.class"
testClassesDirs = sourceSets.test.output.classesDirs
classpath = sourceSets.test.runtimeClasspath
inputs.dir(file("src/testKit"))
// tell BuildExamplePluginsIT where to find the example plugins
systemProperty (
Expand All @@ -229,7 +232,11 @@ if (project != rootProject) {
if (isLuceneSnapshot) {
systemProperty 'test.lucene-snapshot-revision', isLuceneSnapshot[0][1]
}
maxParallelForks System.getProperty('tests.jvms', project.rootProject.ext.defaultParallel.toString()) as Integer
String defaultParallel = System.getProperty('tests.jvms', project.rootProject.ext.defaultParallel)
if (defaultParallel == "auto") {
defaultParallel = Math.max(Runtime.getRuntime().availableProcessors(), 4)
}
maxParallelForks defaultParallel as Integer
}
check.dependsOn(integTest)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.carrotsearch.gradle.junit4

import com.carrotsearch.ant.tasks.junit4.SuiteBalancer
import com.carrotsearch.ant.tasks.junit4.balancers.ExecutionTimeBalancer
import com.carrotsearch.ant.tasks.junit4.listeners.ExecutionTimesReport
import org.apache.tools.ant.types.FileSet

class BalancersConfiguration {
// parent task, so executionTime can register an additional listener
RandomizedTestingTask task
List<SuiteBalancer> balancers = new ArrayList<>()

void executionTime(Map<String,Object> properties) {
ExecutionTimeBalancer balancer = new ExecutionTimeBalancer()

FileSet fileSet = new FileSet()
Object filename = properties.remove('cacheFilename')
if (filename == null) {
throw new IllegalArgumentException('cacheFilename is required for executionTime balancer')
}
fileSet.setIncludes(filename.toString())

File cacheDir = task.project.projectDir
Object dir = properties.remove('cacheDir')
if (dir != null) {
cacheDir = new File(dir.toString())
}
fileSet.setDir(cacheDir)
balancer.add(fileSet)

int historySize = 10
Object size = properties.remove('historySize')
if (size instanceof Integer) {
historySize = (Integer)size
} else if (size != null) {
throw new IllegalArgumentException('historySize must be an integer')
}
ExecutionTimesReport listener = new ExecutionTimesReport()
listener.setFile(new File(cacheDir, filename.toString()))
listener.setHistoryLength(historySize)

if (properties.isEmpty() == false) {
throw new IllegalArgumentException('Unknown properties for executionTime balancer: ' + properties.keySet())
}

task.listenersConfig.listeners.add(listener)
balancers.add(balancer)
}

void custom(SuiteBalancer balancer) {
balancers.add(balancer)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.carrotsearch.gradle.junit4

import com.carrotsearch.ant.tasks.junit4.listeners.AggregatedEventListener
import com.carrotsearch.ant.tasks.junit4.listeners.antxml.AntXmlReport


class ListenersConfiguration {
RandomizedTestingTask task
List<AggregatedEventListener> listeners = new ArrayList<>()

void junitReport(Map<String, Object> props) {
AntXmlReport reportListener = new AntXmlReport()
Object dir = props == null ? null : props.get('dir')
if (dir != null) {
reportListener.setDir(task.project.file(dir))
} else {
reportListener.setDir(new File(task.project.buildDir, 'reports' + File.separator + "${task.name}Junit"))
}
listeners.add(reportListener)
}

void custom(AggregatedEventListener listener) {
listeners.add(listener)
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.elasticsearch.gradle
package com.carrotsearch.gradle.junit4

import org.gradle.api.logging.LogLevel
import org.gradle.api.logging.Logger
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.carrotsearch.gradle.junit4

import com.carrotsearch.ant.tasks.junit4.JUnit4
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.tasks.TaskContainer

class RandomizedTestingPlugin implements Plugin<Project> {

void apply(Project project) {
String seed = setupSeed(project)
createUnitTestTask(project.tasks)
configureAnt(project.ant, seed)
}

/**
* Pins the test seed at configuration time so it isn't different on every
* {@link RandomizedTestingTask} execution. This is useful if random
* decisions in one run of {@linkplain RandomizedTestingTask} influence the
* outcome of subsequent runs. Pinning the seed up front like this makes
* the reproduction line from one run be useful on another run.
*/
static String setupSeed(Project project) {
if (project.rootProject.ext.has('testSeed')) {
/* Skip this if we've already pinned the testSeed. It is important
* that this checks the rootProject so that we know we've only ever
* initialized one time. */
return project.rootProject.ext.testSeed
}
String testSeed = System.getProperty('tests.seed')
if (testSeed == null) {
long seed = new Random(System.currentTimeMillis()).nextLong()
testSeed = Long.toUnsignedString(seed, 16).toUpperCase(Locale.ROOT)
}
/* Set the testSeed on the root project first so other projects can use
* it during initialization. */
project.rootProject.ext.testSeed = testSeed
project.rootProject.subprojects {
project.ext.testSeed = testSeed
}

return testSeed
}

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
}
}

static void configureAnt(AntBuilder ant, String seed) {
ant.project.addTaskDefinition('junit4:junit4', JUnit4.class)
ant.properties.put('tests.seed', seed)
}
}
Loading

0 comments on commit 9a1fd06

Please sign in to comment.