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) {
|
private void configureTestConventions(Project project) {
|
||||||
project.getPlugins().apply(TestRetryPlugin.class);
|
if (Boolean.valueOf(System.getenv("CI"))) {
|
||||||
project.getTasks().withType(Test.class, (test) -> {
|
project.getPlugins().apply(TestRetryPlugin.class);
|
||||||
withOptionalBuildJavaHome(project, (javaHome) -> test.setExecutable(javaHome + "/bin/java"));
|
project.getTasks().withType(Test.class, (test) -> {
|
||||||
test.useJUnitPlatform();
|
withOptionalBuildJavaHome(project, (javaHome) -> test.setExecutable(javaHome + "/bin/java"));
|
||||||
test.setMaxHeapSize("1024M");
|
test.useJUnitPlatform();
|
||||||
project.getPlugins().withType(TestRetryPlugin.class, (testRetryPlugin) -> {
|
test.setMaxHeapSize("1024M");
|
||||||
TestRetryTaskExtension testRetry = test.getExtensions().getByType(TestRetryTaskExtension.class);
|
project.getPlugins().withType(TestRetryPlugin.class, (testRetryPlugin) -> {
|
||||||
testRetry.getFailOnPassedAfterRetry().set(true);
|
TestRetryTaskExtension testRetry = test.getExtensions().getByType(TestRetryTaskExtension.class);
|
||||||
testRetry.getMaxRetries().set(3);
|
testRetry.getFailOnPassedAfterRetry().set(true);
|
||||||
|
testRetry.getMaxRetries().set(3);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void configureJavadocConventions(Project project) {
|
private void configureJavadocConventions(Project project) {
|
||||||
|
@ -21,6 +21,8 @@ import java.io.FileWriter;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.jar.JarEntry;
|
import java.util.jar.JarEntry;
|
||||||
import java.util.jar.JarFile;
|
import java.util.jar.JarFile;
|
||||||
|
|
||||||
@ -76,7 +78,7 @@ class ConventionsPluginTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testRetryIsConfigured() throws IOException {
|
void testRetryIsConfiguredOnCI() throws IOException {
|
||||||
try (PrintWriter out = new PrintWriter(new FileWriter(this.buildFile))) {
|
try (PrintWriter out = new PrintWriter(new FileWriter(this.buildFile))) {
|
||||||
out.println("plugins {");
|
out.println("plugins {");
|
||||||
out.println(" id 'java'");
|
out.println(" id 'java'");
|
||||||
@ -85,6 +87,7 @@ class ConventionsPluginTests {
|
|||||||
out.println("description 'Test'");
|
out.println("description 'Test'");
|
||||||
out.println("task retryConfig {");
|
out.println("task retryConfig {");
|
||||||
out.println(" doLast {");
|
out.println(" doLast {");
|
||||||
|
out.println(" println \"Retry plugin applied: ${plugins.hasPlugin('org.gradle.test-retry')}\"");
|
||||||
out.println(" test.retry {");
|
out.println(" test.retry {");
|
||||||
out.println(" println \"maxRetries: ${maxRetries.get()}\"");
|
out.println(" println \"maxRetries: ${maxRetries.get()}\"");
|
||||||
out.println(" println \"failOnPassedAfterRetry: ${failOnPassedAfterRetry.get()}\"");
|
out.println(" println \"failOnPassedAfterRetry: ${failOnPassedAfterRetry.get()}\"");
|
||||||
@ -92,12 +95,36 @@ class ConventionsPluginTests {
|
|||||||
out.println(" }");
|
out.println(" }");
|
||||||
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");
|
.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) {
|
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