Skip to content

Commit 080123e

Browse files
committed
Only enable flaky test support on CI
Closes gh-21272
1 parent 79a2e7f commit 080123e

File tree

2 files changed

+42
-13
lines changed

2 files changed

+42
-13
lines changed

buildSrc/src/main/java/org/springframework/boot/build/JavaConventions.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -107,17 +107,19 @@ private void configureJarManifestConventions(Project project) {
107107
}
108108

109109
private void configureTestConventions(Project project) {
110-
project.getPlugins().apply(TestRetryPlugin.class);
111-
project.getTasks().withType(Test.class, (test) -> {
112-
withOptionalBuildJavaHome(project, (javaHome) -> test.setExecutable(javaHome + "/bin/java"));
113-
test.useJUnitPlatform();
114-
test.setMaxHeapSize("1024M");
115-
project.getPlugins().withType(TestRetryPlugin.class, (testRetryPlugin) -> {
116-
TestRetryTaskExtension testRetry = test.getExtensions().getByType(TestRetryTaskExtension.class);
117-
testRetry.getFailOnPassedAfterRetry().set(true);
118-
testRetry.getMaxRetries().set(3);
110+
if (Boolean.valueOf(System.getenv("CI"))) {
111+
project.getPlugins().apply(TestRetryPlugin.class);
112+
project.getTasks().withType(Test.class, (test) -> {
113+
withOptionalBuildJavaHome(project, (javaHome) -> test.setExecutable(javaHome + "/bin/java"));
114+
test.useJUnitPlatform();
115+
test.setMaxHeapSize("1024M");
116+
project.getPlugins().withType(TestRetryPlugin.class, (testRetryPlugin) -> {
117+
TestRetryTaskExtension testRetry = test.getExtensions().getByType(TestRetryTaskExtension.class);
118+
testRetry.getFailOnPassedAfterRetry().set(true);
119+
testRetry.getMaxRetries().set(3);
120+
});
119121
});
120-
});
122+
}
121123
}
122124

123125
private void configureJavadocConventions(Project project) {

buildSrc/src/test/java/org/springframework/boot/build/ConventionsPluginTests.java

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
import java.io.IOException;
2222
import java.io.InputStreamReader;
2323
import java.io.PrintWriter;
24+
import java.util.Collections;
25+
import java.util.Map;
2426
import java.util.jar.JarEntry;
2527
import java.util.jar.JarFile;
2628

@@ -76,7 +78,7 @@ void jarIncludesLegalFiles() throws IOException {
7678
}
7779

7880
@Test
79-
void testRetryIsConfigured() throws IOException {
81+
void testRetryIsConfiguredOnCI() throws IOException {
8082
try (PrintWriter out = new PrintWriter(new FileWriter(this.buildFile))) {
8183
out.println("plugins {");
8284
out.println(" id 'java'");
@@ -85,19 +87,44 @@ void testRetryIsConfigured() throws IOException {
8587
out.println("description 'Test'");
8688
out.println("task retryConfig {");
8789
out.println(" doLast {");
90+
out.println(" println \"Retry plugin applied: ${plugins.hasPlugin('org.gradle.test-retry')}\"");
8891
out.println(" test.retry {");
8992
out.println(" println \"maxRetries: ${maxRetries.get()}\"");
9093
out.println(" println \"failOnPassedAfterRetry: ${failOnPassedAfterRetry.get()}\"");
9194
out.println(" }");
9295
out.println(" }");
9396
out.println("}");
9497
}
95-
assertThat(runGradle("retryConfig", "--stacktrace").getOutput()).contains("maxRetries: 3")
98+
assertThat(runGradle(Collections.singletonMap("CI", "true"), "retryConfig", "--stacktrace").getOutput())
99+
.contains("Retry plugin applied: true").contains("maxRetries: 3")
96100
.contains("failOnPassedAfterRetry: true");
97101
}
98102

103+
@Test
104+
void testRetryIsNotConfiguredLocally() throws IOException {
105+
try (PrintWriter out = new PrintWriter(new FileWriter(this.buildFile))) {
106+
out.println("plugins {");
107+
out.println(" id 'java'");
108+
out.println(" id 'org.springframework.boot.conventions'");
109+
out.println("}");
110+
out.println("description 'Test'");
111+
out.println("task retryConfig {");
112+
out.println(" doLast {");
113+
out.println(" println \"Retry plugin applied: ${plugins.hasPlugin('org.gradle.test-retry')}\"");
114+
out.println(" }");
115+
out.println("}");
116+
}
117+
assertThat(runGradle(Collections.singletonMap("CI", "local"), "retryConfig", "--stacktrace").getOutput())
118+
.contains("Retry plugin applied: false");
119+
}
120+
99121
private BuildResult runGradle(String... args) {
100-
return GradleRunner.create().withProjectDir(this.projectDir).withArguments(args).withPluginClasspath().build();
122+
return runGradle(Collections.emptyMap(), args);
123+
}
124+
125+
private BuildResult runGradle(Map<String, String> environment, String... args) {
126+
return GradleRunner.create().withProjectDir(this.projectDir).withEnvironment(environment).withArguments(args)
127+
.withPluginClasspath().build();
101128
}
102129

103130
}

0 commit comments

Comments
 (0)