Skip to content

Commit ecf7bb0

Browse files
authored
Ensure global test seed is used for all random testing tasks (#38991) (#39197)
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. * Use explicit type
1 parent a4485f2 commit ecf7bb0

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

buildSrc/src/main/groovy/com/carrotsearch/gradle/junit4/RandomizedTestingPlugin.groovy

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@ package com.carrotsearch.gradle.junit4
33
import com.carrotsearch.ant.tasks.junit4.JUnit4
44
import org.gradle.api.Plugin
55
import org.gradle.api.Project
6-
import org.gradle.api.Task
76
import org.gradle.api.tasks.TaskContainer
87

98
class RandomizedTestingPlugin implements Plugin<Project> {
109

1110
void apply(Project project) {
12-
setupSeed(project)
11+
String seed = setupSeed(project)
1312
createUnitTestTask(project.tasks)
14-
configureAnt(project.ant)
13+
configureAnt(project.ant, seed)
1514
}
1615

1716
/**
@@ -21,12 +20,12 @@ class RandomizedTestingPlugin implements Plugin<Project> {
2120
* outcome of subsequent runs. Pinning the seed up front like this makes
2221
* the reproduction line from one run be useful on another run.
2322
*/
24-
static void setupSeed(Project project) {
23+
static String setupSeed(Project project) {
2524
if (project.rootProject.ext.has('testSeed')) {
2625
/* Skip this if we've already pinned the testSeed. It is important
2726
* that this checks the rootProject so that we know we've only ever
2827
* initialized one time. */
29-
return
28+
return project.rootProject.ext.testSeed
3029
}
3130
String testSeed = System.getProperty('tests.seed')
3231
if (testSeed == null) {
@@ -39,6 +38,8 @@ class RandomizedTestingPlugin implements Plugin<Project> {
3938
project.rootProject.subprojects {
4039
project.ext.testSeed = testSeed
4140
}
41+
42+
return testSeed
4243
}
4344

4445
static void createUnitTestTask(TaskContainer tasks) {
@@ -52,7 +53,8 @@ class RandomizedTestingPlugin implements Plugin<Project> {
5253
}
5354
}
5455

55-
static void configureAnt(AntBuilder ant) {
56+
static void configureAnt(AntBuilder ant, String seed) {
5657
ant.project.addTaskDefinition('junit4:junit4', JUnit4.class)
58+
ant.properties.put('tests.seed', seed)
5759
}
5860
}

0 commit comments

Comments
 (0)