Skip to content

Commit 4b47fb1

Browse files
authored
Correct tests.seed to be reported on failures (#14848)
1 parent 51e6fbb commit 4b47fb1

File tree

3 files changed

+46
-9
lines changed

3 files changed

+46
-9
lines changed

build-tools/build-infra/src/main/groovy/lucene.java.show-failed-tests-at-end.gradle

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
* limitations under the License.
1616
*/
1717

18+
import java.util.regex.Pattern
1819
import org.apache.lucene.gradle.ErrorReportingTestListener
1920

2021
// Display all failed tests at the end of the build.
@@ -33,11 +34,28 @@ allprojects {
3334

3435
afterTest { desc, result ->
3536
if (result.resultType == TestResult.ResultType.FAILURE) {
37+
// check if it's a constructor or a before/after class hook that failed.
38+
def qTestName
39+
if (desc.name == "classMethod") {
40+
qTestName = desc.className
41+
} else {
42+
qTestName = "${desc.className}.${desc.name}"
43+
}
44+
45+
def randomizationParameters = ""
46+
def p = Pattern.compile(/.+ (?<params>[{].*[}])$/)
47+
def matcher = p.matcher(qTestName)
48+
if (matcher.matches()) {
49+
randomizationParameters = matcher.group("params")
50+
qTestName = qTestName.replace(randomizationParameters, "").trim()
51+
}
52+
3653
failedTests << [
37-
"name" : "${desc.className}.${desc.name}",
54+
"name" : qTestName,
55+
"randomizationParameters": randomizationParameters,
3856
"project" : "${test.project.path}",
3957
"output" : file("${testOutputsDir}/${ErrorReportingTestListener.getOutputLogName(desc.parent)}"),
40-
"reproduce": "gradlew ${project.path}:test --tests \"${desc.className}.${desc.name}\" ${reproLine}"
58+
"reproduce": "gradlew ${project.path}:test --tests \"${qTestName}\" ${reproLine}"
4159
]
4260
}
4361
}
@@ -62,11 +80,14 @@ gradle.buildFinished { result ->
6280
.sort { a, b -> b.project.compareTo(a.project) }
6381
.collect { e ->
6482
String.format(Locale.ROOT,
65-
" - %s (%s)\n Test output: %s\n Reproduce with: %s\n",
66-
e.name, e.project, e.output, e.reproduce)
83+
" - %s (%s)%s\n Test output: %s\n Reproduce with: %s\n",
84+
e.name, e.project,
85+
e.containsKey("randomizationParameters") &&
86+
!e.randomizationParameters.isBlank() ? "\n Context parameters: ${e.randomizationParameters}" : "",
87+
e.output, e.reproduce)
6788
}
6889
.join("\n")
6990

70-
logger.error("\nERROR: The following test(s) have failed:\n${formatted}")
91+
logger.error("\nERROR: The following {} failed:\n\n{}", failedTests.size() == 1 ? "test has" : "tests have", formatted)
7192
}
7293
}

build-tools/build-infra/src/main/groovy/lucene.java.tests-and-randomization.gradle

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import org.apache.tools.ant.types.Commandline
2020
import org.gradle.api.tasks.testing.logging.*
2121
import com.carrotsearch.randomizedtesting.generators.RandomPicks
2222
import org.apache.lucene.gradle.ErrorReportingTestListener
23+
import com.carrotsearch.gradle.buildinfra.buildoptions.BuildOptionsExtension
2324

2425
def loggingConfigFile = rootProject.layout.projectDirectory.file("gradle/testing/logging.properties")
2526
def verboseModeHookInstalled = false
@@ -82,6 +83,13 @@ Provider<Integer> upperJavaFeatureVersionOption = buildOptions.addIntOption(
8283
"tests.upperJavaFeatureVersion", "Min JDK feature version to configure the Panama Vectorization provider")
8384

8485
// Test reiteration, filtering and component randomization options.
86+
87+
// Propagate root seed so that it is visible and reported as an option in subprojects.
88+
if (project != project.rootProject) {
89+
buildOptions.addOption("tests.seed", "The \"root\" randomization seed for options and test parameters.",
90+
rootProject.getExtensions().getByType(BuildOptionsExtension).getOption("tests.seed").asStringProvider())
91+
}
92+
8593
buildOptions.addIntOption("tests.iters", "Duplicate (re-run) each test case N times.")
8694
optionsInheritedAsProperties += ["tests.iters"]
8795

build-tools/build-infra/src/main/java/org/apache/lucene/gradle/ErrorReportingTestListener.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,19 @@ public static String getReproLineOptions(Test testTask) {
173173
})
174174
.filter(
175175
option -> {
176+
// if the option is not present, ignore it in repro line.
177+
if (!option.isPresent()) {
178+
return false;
179+
}
180+
176181
// we only care about options that have non-default values or options
177-
// where values are computed are runtime (possibly randomized).
178-
return option.isPresent()
179-
&& (option.getSource() == BuildOptionValueSource.COMPUTED_VALUE
180-
|| !option.isEqualToDefaultValue());
182+
// where values are computed at runtime (possibly randomized).
183+
if (option.getSource() == BuildOptionValueSource.COMPUTED_VALUE) {
184+
return true;
185+
}
186+
187+
// filter out all non-computed options with default values.
188+
return !option.isEqualToDefaultValue();
181189
})
182190
.map(
183191
option -> {

0 commit comments

Comments
 (0)