From 0f68814e048351c34fb91283bc45c28958999b86 Mon Sep 17 00:00:00 2001 From: Mark Vieira Date: Thu, 21 Feb 2019 08:52:14 -0800 Subject: [PATCH] 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. --- .../gradle/junit4/RandomizedTestingPlugin.groovy | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/buildSrc/src/main/groovy/com/carrotsearch/gradle/junit4/RandomizedTestingPlugin.groovy b/buildSrc/src/main/groovy/com/carrotsearch/gradle/junit4/RandomizedTestingPlugin.groovy index 3b0348b4899..7d554386c39 100644 --- a/buildSrc/src/main/groovy/com/carrotsearch/gradle/junit4/RandomizedTestingPlugin.groovy +++ b/buildSrc/src/main/groovy/com/carrotsearch/gradle/junit4/RandomizedTestingPlugin.groovy @@ -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 { 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 { * 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.rootProject.subprojects { project.ext.testSeed = testSeed } + + return testSeed } static void createUnitTestTask(TaskContainer tasks) { @@ -52,7 +53,8 @@ class RandomizedTestingPlugin implements Plugin { } } - 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) } }