Skip to content

Commit 55f4988

Browse files
authored
Move test seed setup to global build info (#47763)
The global build info plugin prints high level information about the build, including the test seed. However, BuildPlugin sets up the test seed, which creates an odd implicit dependency on it. This commit moves the intialization of the testSeed property into the global build info.
1 parent d680ca3 commit 55f4988

File tree

2 files changed

+12
-28
lines changed

2 files changed

+12
-28
lines changed

buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy

-27
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ class BuildPlugin implements Plugin<Project> {
131131

132132
project.getTasks().register("buildResources", ExportElasticsearchBuildResourcesTask)
133133

134-
setupSeed(project)
135134
configureRepositories(project)
136135
project.extensions.getByType(ExtraPropertiesExtension).set('versions', VersionProperties.versions)
137136
configureInputNormalization(project)
@@ -950,32 +949,6 @@ class BuildPlugin implements Plugin<Project> {
950949
}
951950
}
952951

953-
/**
954-
* Pins the test seed at configuration time so it isn't different on every
955-
* {@link Test} execution. This is useful if random
956-
* decisions in one run of {@linkplain Test} influence the
957-
* outcome of subsequent runs. Pinning the seed up front like this makes
958-
* the reproduction line from one run be useful on another run.
959-
*/
960-
static String setupSeed(Project project) {
961-
ExtraPropertiesExtension ext = project.rootProject.extensions.getByType(ExtraPropertiesExtension)
962-
if (ext.has('testSeed')) {
963-
/* Skip this if we've already pinned the testSeed. It is important
964-
* that this checks the rootProject so that we know we've only ever
965-
* initialized one time. */
966-
return ext.get('testSeed')
967-
}
968-
969-
String testSeed = System.getProperty('tests.seed')
970-
if (testSeed == null) {
971-
long seed = new Random(System.currentTimeMillis()).nextLong()
972-
testSeed = Long.toUnsignedString(seed, 16).toUpperCase(Locale.ROOT)
973-
}
974-
975-
ext.set('testSeed', testSeed)
976-
return testSeed
977-
}
978-
979952
private static class TestFailureReportingPlugin implements Plugin<Project> {
980953
@Override
981954
void apply(Project project) {

buildSrc/src/main/java/org/elasticsearch/gradle/info/GlobalBuildInfoPlugin.java

+12-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525
import java.util.Arrays;
2626
import java.util.HashMap;
2727
import java.util.List;
28+
import java.util.Locale;
2829
import java.util.Map;
30+
import java.util.Random;
2931
import java.util.stream.Collectors;
3032

3133
public class GlobalBuildInfoPlugin implements Plugin<Project> {
@@ -46,6 +48,15 @@ public void apply(Project project) {
4648
File compilerJavaHome = findCompilerJavaHome();
4749
File runtimeJavaHome = findRuntimeJavaHome(compilerJavaHome);
4850

51+
String testSeedProperty = System.getProperty("tests.seed");
52+
final String testSeed;
53+
if (testSeedProperty == null) {
54+
long seed = new Random(System.currentTimeMillis()).nextLong();
55+
testSeed = Long.toUnsignedString(seed, 16).toUpperCase(Locale.ROOT);
56+
} else {
57+
testSeed = testSeedProperty;
58+
}
59+
4960
final List<JavaHome> javaVersions = new ArrayList<>();
5061
for (int version = 8; version <= Integer.parseInt(minimumCompilerVersion.getMajorVersion()); version++) {
5162
if (System.getenv(getJavaHomeEnvVarName(Integer.toString(version))) != null) {
@@ -95,6 +106,7 @@ public void apply(Project project) {
95106
ext.set("gradleJavaVersion", Jvm.current().getJavaVersion());
96107
ext.set("gitRevision", gitRevision(project.getRootProject().getRootDir()));
97108
ext.set("buildDate", ZonedDateTime.now(ZoneOffset.UTC));
109+
ext.set("testSeed", testSeed);
98110
ext.set("isCi", System.getenv("JENKINS_URL") != null);
99111
});
100112
}
@@ -265,5 +277,4 @@ private static String readFirstLine(final Path path) throws IOException {
265277
.findFirst()
266278
.orElseThrow(() -> new IOException("file [" + path + "] is empty"));
267279
}
268-
269280
}

0 commit comments

Comments
 (0)