mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
Only enable flaky test support on CI
Closes gh-21272
This commit is contained in:
parent
79a2e7f469
commit
080123ebeb
@ -107,17 +107,19 @@ class JavaConventions {
|
||||
}
|
||||
|
||||
private void configureTestConventions(Project project) {
|
||||
project.getPlugins().apply(TestRetryPlugin.class);
|
||||
project.getTasks().withType(Test.class, (test) -> {
|
||||
withOptionalBuildJavaHome(project, (javaHome) -> test.setExecutable(javaHome + "/bin/java"));
|
||||
test.useJUnitPlatform();
|
||||
test.setMaxHeapSize("1024M");
|
||||
project.getPlugins().withType(TestRetryPlugin.class, (testRetryPlugin) -> {
|
||||
TestRetryTaskExtension testRetry = test.getExtensions().getByType(TestRetryTaskExtension.class);
|
||||
testRetry.getFailOnPassedAfterRetry().set(true);
|
||||
testRetry.getMaxRetries().set(3);
|
||||
if (Boolean.valueOf(System.getenv("CI"))) {
|
||||
project.getPlugins().apply(TestRetryPlugin.class);
|
||||
project.getTasks().withType(Test.class, (test) -> {
|
||||
withOptionalBuildJavaHome(project, (javaHome) -> test.setExecutable(javaHome + "/bin/java"));
|
||||
test.useJUnitPlatform();
|
||||
test.setMaxHeapSize("1024M");
|
||||
project.getPlugins().withType(TestRetryPlugin.class, (testRetryPlugin) -> {
|
||||
TestRetryTaskExtension testRetry = test.getExtensions().getByType(TestRetryTaskExtension.class);
|
||||
testRetry.getFailOnPassedAfterRetry().set(true);
|
||||
testRetry.getMaxRetries().set(3);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void configureJavadocConventions(Project project) {
|
||||
|
@ -21,6 +21,8 @@ import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarFile;
|
||||
|
||||
@ -76,7 +78,7 @@ class ConventionsPluginTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testRetryIsConfigured() throws IOException {
|
||||
void testRetryIsConfiguredOnCI() throws IOException {
|
||||
try (PrintWriter out = new PrintWriter(new FileWriter(this.buildFile))) {
|
||||
out.println("plugins {");
|
||||
out.println(" id 'java'");
|
||||
@ -85,6 +87,7 @@ class ConventionsPluginTests {
|
||||
out.println("description 'Test'");
|
||||
out.println("task retryConfig {");
|
||||
out.println(" doLast {");
|
||||
out.println(" println \"Retry plugin applied: ${plugins.hasPlugin('org.gradle.test-retry')}\"");
|
||||
out.println(" test.retry {");
|
||||
out.println(" println \"maxRetries: ${maxRetries.get()}\"");
|
||||
out.println(" println \"failOnPassedAfterRetry: ${failOnPassedAfterRetry.get()}\"");
|
||||
@ -92,12 +95,36 @@ class ConventionsPluginTests {
|
||||
out.println(" }");
|
||||
out.println("}");
|
||||
}
|
||||
assertThat(runGradle("retryConfig", "--stacktrace").getOutput()).contains("maxRetries: 3")
|
||||
assertThat(runGradle(Collections.singletonMap("CI", "true"), "retryConfig", "--stacktrace").getOutput())
|
||||
.contains("Retry plugin applied: true").contains("maxRetries: 3")
|
||||
.contains("failOnPassedAfterRetry: true");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testRetryIsNotConfiguredLocally() throws IOException {
|
||||
try (PrintWriter out = new PrintWriter(new FileWriter(this.buildFile))) {
|
||||
out.println("plugins {");
|
||||
out.println(" id 'java'");
|
||||
out.println(" id 'org.springframework.boot.conventions'");
|
||||
out.println("}");
|
||||
out.println("description 'Test'");
|
||||
out.println("task retryConfig {");
|
||||
out.println(" doLast {");
|
||||
out.println(" println \"Retry plugin applied: ${plugins.hasPlugin('org.gradle.test-retry')}\"");
|
||||
out.println(" }");
|
||||
out.println("}");
|
||||
}
|
||||
assertThat(runGradle(Collections.singletonMap("CI", "local"), "retryConfig", "--stacktrace").getOutput())
|
||||
.contains("Retry plugin applied: false");
|
||||
}
|
||||
|
||||
private BuildResult runGradle(String... args) {
|
||||
return GradleRunner.create().withProjectDir(this.projectDir).withArguments(args).withPluginClasspath().build();
|
||||
return runGradle(Collections.emptyMap(), args);
|
||||
}
|
||||
|
||||
private BuildResult runGradle(Map<String, String> environment, String... args) {
|
||||
return GradleRunner.create().withProjectDir(this.projectDir).withEnvironment(environment).withArguments(args)
|
||||
.withPluginClasspath().build();
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user