Skip to content

[Backport 6.7] Ensure global test seed is used for all random testing tasks (#38991) #39197

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 21, 2019
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

/**
Expand All @@ -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) {
Expand All @@ -39,6 +38,8 @@ class RandomizedTestingPlugin implements Plugin<Project> {
project.rootProject.subprojects {
project.ext.testSeed = testSeed
}

return testSeed
}

static void createUnitTestTask(TaskContainer tasks) {
Expand All @@ -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)
}
}