Skip to content

Commit 7490f5f

Browse files
authored
Make ErrorReportingTestListener Gradle configuration cache compatible (#109415)
and make it a bit simpler too
1 parent 7e7f8a3 commit 7490f5f

File tree

2 files changed

+8
-13
lines changed

2 files changed

+8
-13
lines changed

build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/test/ErrorReportingTestListener.java

+6-11
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
*/
88
package org.elasticsearch.gradle.internal.test;
99

10-
import org.elasticsearch.gradle.internal.ElasticsearchTestBasePlugin;
1110
import org.gradle.api.internal.tasks.testing.logging.FullExceptionFormatter;
1211
import org.gradle.api.internal.tasks.testing.logging.TestExceptionFormatter;
1312
import org.gradle.api.logging.Logger;
@@ -39,21 +38,24 @@
3938
public class ErrorReportingTestListener implements TestOutputListener, TestListener {
4039
private static final String REPRODUCE_WITH_PREFIX = "REPRODUCE WITH";
4140

42-
private final Test testTask;
4341
private final TestExceptionFormatter formatter;
4442
private final File outputDirectory;
4543
private final Logger taskLogger;
4644
private Map<Descriptor, EventWriter> eventWriters = new ConcurrentHashMap<>();
4745
private Map<Descriptor, Deque<String>> reproductionLines = new ConcurrentHashMap<>();
4846
private Set<Descriptor> failedTests = new LinkedHashSet<>();
47+
private boolean dumpOutputOnFailure = true;
4948

5049
public ErrorReportingTestListener(Test testTask, File outputDirectory) {
51-
this.testTask = testTask;
5250
this.formatter = new FullExceptionFormatter(testTask.getTestLogging());
5351
this.taskLogger = testTask.getLogger();
5452
this.outputDirectory = outputDirectory;
5553
}
5654

55+
public void setDumpOutputOnFailure(boolean dumpOutputOnFailure) {
56+
this.dumpOutputOnFailure = dumpOutputOnFailure;
57+
}
58+
5759
@Override
5860
public void onOutput(TestDescriptor testDescriptor, TestOutputEvent outputEvent) {
5961
TestDescriptor suite = testDescriptor.getParent();
@@ -83,7 +85,7 @@ public void afterSuite(final TestDescriptor suite, TestResult result) {
8385
Descriptor descriptor = Descriptor.of(suite);
8486

8587
try {
86-
if (isDumpOutputEnabled()) {
88+
if (dumpOutputOnFailure) {
8789
// if the test suite failed, report all captured output
8890
if (result.getResultType().equals(TestResult.ResultType.FAILURE)) {
8991
EventWriter eventWriter = eventWriters.get(descriptor);
@@ -256,11 +258,4 @@ public void close() throws IOException {
256258
outputFile.delete();
257259
}
258260
}
259-
260-
private boolean isDumpOutputEnabled() {
261-
return (Boolean) testTask.getExtensions()
262-
.getExtraProperties()
263-
.getProperties()
264-
.getOrDefault(ElasticsearchTestBasePlugin.DUMP_OUTPUT_ON_FAILURE_PROP_NAME, true);
265-
}
266261
}

build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/test/rest/RestTestBasePlugin.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
import org.elasticsearch.gradle.VersionProperties;
1919
import org.elasticsearch.gradle.distribution.ElasticsearchDistributionTypes;
2020
import org.elasticsearch.gradle.internal.ElasticsearchJavaPlugin;
21-
import org.elasticsearch.gradle.internal.ElasticsearchTestBasePlugin;
2221
import org.elasticsearch.gradle.internal.InternalDistributionDownloadPlugin;
2322
import org.elasticsearch.gradle.internal.info.BuildParams;
23+
import org.elasticsearch.gradle.internal.test.ErrorReportingTestListener;
2424
import org.elasticsearch.gradle.internal.test.HistoricalFeaturesMetadataPlugin;
2525
import org.elasticsearch.gradle.plugin.BasePluginBuildPlugin;
2626
import org.elasticsearch.gradle.plugin.PluginBuildPlugin;
@@ -167,7 +167,7 @@ public void apply(Project project) {
167167
nonInputSystemProperties.systemProperty(TESTS_MAX_PARALLEL_FORKS_SYSPROP, () -> String.valueOf(task.getMaxParallelForks()));
168168

169169
// Disable test failure reporting since this stuff is now captured in build scans
170-
task.getExtensions().getExtraProperties().set(ElasticsearchTestBasePlugin.DUMP_OUTPUT_ON_FAILURE_PROP_NAME, false);
170+
task.getExtensions().getByType(ErrorReportingTestListener.class).setDumpOutputOnFailure(false);
171171

172172
// Disable the security manager and syscall filter since the test framework needs to fork processes
173173
task.systemProperty("tests.security.manager", "false");

0 commit comments

Comments
 (0)