Skip to content

Commit 813f44c

Browse files
committed
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 12e4e7e commit 813f44c

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
@@ -129,7 +129,6 @@ class BuildPlugin implements Plugin<Project> {
129129

130130
project.getTasks().register("buildResources", ExportElasticsearchBuildResourcesTask)
131131

132-
setupSeed(project)
133132
configureRepositories(project)
134133
project.extensions.getByType(ExtraPropertiesExtension).set('versions', VersionProperties.versions)
135134
configureInputNormalization(project)
@@ -963,32 +962,6 @@ class BuildPlugin implements Plugin<Project> {
963962
}
964963
}
965964

966-
/**
967-
* Pins the test seed at configuration time so it isn't different on every
968-
* {@link Test} execution. This is useful if random
969-
* decisions in one run of {@linkplain Test} influence the
970-
* outcome of subsequent runs. Pinning the seed up front like this makes
971-
* the reproduction line from one run be useful on another run.
972-
*/
973-
static String setupSeed(Project project) {
974-
ExtraPropertiesExtension ext = project.rootProject.extensions.getByType(ExtraPropertiesExtension)
975-
if (ext.has('testSeed')) {
976-
/* Skip this if we've already pinned the testSeed. It is important
977-
* that this checks the rootProject so that we know we've only ever
978-
* initialized one time. */
979-
return ext.get('testSeed')
980-
}
981-
982-
String testSeed = System.getProperty('tests.seed')
983-
if (testSeed == null) {
984-
long seed = new Random(System.currentTimeMillis()).nextLong()
985-
testSeed = Long.toUnsignedString(seed, 16).toUpperCase(Locale.ROOT)
986-
}
987-
988-
ext.set('testSeed', testSeed)
989-
return testSeed
990-
}
991-
992965
private static class TestFailureReportingPlugin implements Plugin<Project> {
993966
@Override
994967
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)