From c0f748e1436cd44af3a79d2d9953665bf060a3bf Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Thu, 4 Jun 2020 15:42:49 +0100 Subject: [PATCH] Always apply retry plugin but only retry on CI Previously, the retry plugin was only applied on CI as we do not want tests to be retried in local builds. Unfortunately, this arrangement led to test tasks from CI builds having additional doFirst and doLast actions and an additional property. These differences meant that the output from a test task that has run on CI could not be used by a local build. This commit changes our configuration of the test retry plugin so that it is now always applied. To retain the behaviour of only retrying tests on CI, max retries is configured to 3 on CI and 0 for local builds. Closes gh-21698 --- .../boot/build/JavaConventions.java | 20 ++++++++++--------- .../boot/build/ConventionsPluginTests.java | 11 +++++++--- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/buildSrc/src/main/java/org/springframework/boot/build/JavaConventions.java b/buildSrc/src/main/java/org/springframework/boot/build/JavaConventions.java index d6a94ee82ae..62a52ff5c5f 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/JavaConventions.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/JavaConventions.java @@ -109,15 +109,17 @@ class JavaConventions { test.useJUnitPlatform(); test.setMaxHeapSize("1024M"); }); - if (Boolean.parseBoolean(System.getenv("CI"))) { - project.getPlugins().apply(TestRetryPlugin.class); - project.getTasks().withType(Test.class, - (test) -> project.getPlugins().withType(TestRetryPlugin.class, (testRetryPlugin) -> { - TestRetryTaskExtension testRetry = test.getExtensions().getByType(TestRetryTaskExtension.class); - testRetry.getFailOnPassedAfterRetry().set(true); - testRetry.getMaxRetries().set(3); - })); - } + project.getPlugins().apply(TestRetryPlugin.class); + project.getTasks().withType(Test.class, + (test) -> project.getPlugins().withType(TestRetryPlugin.class, (testRetryPlugin) -> { + TestRetryTaskExtension testRetry = test.getExtensions().getByType(TestRetryTaskExtension.class); + testRetry.getFailOnPassedAfterRetry().set(true); + testRetry.getMaxRetries().set(isCi() ? 3 : 0); + })); + } + + private boolean isCi() { + return Boolean.parseBoolean(System.getenv("CI")); } private void configureJavadocConventions(Project project) { diff --git a/buildSrc/src/test/java/org/springframework/boot/build/ConventionsPluginTests.java b/buildSrc/src/test/java/org/springframework/boot/build/ConventionsPluginTests.java index 48bcf842939..4af34be3851 100644 --- a/buildSrc/src/test/java/org/springframework/boot/build/ConventionsPluginTests.java +++ b/buildSrc/src/test/java/org/springframework/boot/build/ConventionsPluginTests.java @@ -78,7 +78,7 @@ class ConventionsPluginTests { } @Test - void testRetryIsConfiguredOnCI() throws IOException { + void testRetryIsConfiguredWithThreeRetriesOnCI() throws IOException { try (PrintWriter out = new PrintWriter(new FileWriter(this.buildFile))) { out.println("plugins {"); out.println(" id 'java'"); @@ -101,7 +101,7 @@ class ConventionsPluginTests { } @Test - void testRetryIsNotConfiguredLocally() throws IOException { + void testRetryIsConfiguredWithZeroRetriesLocally() throws IOException { try (PrintWriter out = new PrintWriter(new FileWriter(this.buildFile))) { out.println("plugins {"); out.println(" id 'java'"); @@ -111,11 +111,16 @@ class ConventionsPluginTests { 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()}\""); + out.println(" }"); out.println(" }"); out.println("}"); } assertThat(runGradle(Collections.singletonMap("CI", "local"), "retryConfig", "--stacktrace").getOutput()) - .contains("Retry plugin applied: false"); + .contains("Retry plugin applied: true").contains("maxRetries: 0") + .contains("failOnPassedAfterRetry: true"); } private BuildResult runGradle(String... args) {