Ensure global test seed is used for all random testing tasks (#38991) (#39195)

This commit fixes a bug which resulted in every RandomizedTestingTask
generating its own unique test seed rather than using the global test
seed generated by the the RandomizedTestingPlugin.

The issue didn't affect build invocations which explicitly ran with
-Dtest.seed. In those cases, the Ant junit task correctly uses the
global seed.

Since the Ant random testing target looks for an Ant project property
for determining the existing seed we now explicitly set this inside
RandomizedTestingPlugin. It just so happens that, incidentally, Ant will
inherit system properties, thus wy the -Dtest.seed mechanism continued
to work.
This commit is contained in:
Mark Vieira 2019-02-21 08:52:14 -08:00 committed by GitHub
parent 4b77d0434a
commit 0f68814e04
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 6 deletions

View File

@ -3,15 +3,14 @@ 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.Task
import org.gradle.api.tasks.TaskContainer
class RandomizedTestingPlugin implements Plugin<Project> {
void apply(Project project) {
setupSeed(project)
String seed = setupSeed(project)
createUnitTestTask(project.tasks)
configureAnt(project.ant)
configureAnt(project.ant, seed)
}
/**
@ -21,12 +20,12 @@ class RandomizedTestingPlugin implements Plugin<Project> {
* outcome of subsequent runs. Pinning the seed up front like this makes
* the reproduction line from one run be useful on another run.
*/
static void setupSeed(Project project) {
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
return project.rootProject.ext.testSeed
}
String testSeed = System.getProperty('tests.seed')
if (testSeed == null) {
@ -39,6 +38,8 @@ class RandomizedTestingPlugin implements Plugin<Project> {
project.rootProject.subprojects {
project.ext.testSeed = testSeed
}
return testSeed
}
static void createUnitTestTask(TaskContainer tasks) {
@ -52,7 +53,8 @@ class RandomizedTestingPlugin implements Plugin<Project> {
}
}
static void configureAnt(AntBuilder ant) {
static void configureAnt(AntBuilder ant, String seed) {
ant.project.addTaskDefinition('junit4:junit4', JUnit4.class)
ant.properties.put('tests.seed', seed)
}
}