Skip to content

Commit 7d1cc78

Browse files
committed
Retry on failed plainWar test
Add retry logic for plainWar in an attempt to deal with flaky Tomcat downloads.
1 parent a20cc3d commit 7d1cc78

File tree

1 file changed

+26
-1
lines changed
  • spring-boot-system-tests/spring-boot-image-tests/src/systemTest/java/org/springframework/boot/image/paketo

1 file changed

+26
-1
lines changed

spring-boot-system-tests/spring-boot-image-tests/src/systemTest/java/org/springframework/boot/image/paketo/PaketoBuilderTests.java

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.io.FileWriter;
2121
import java.io.IOException;
2222
import java.io.PrintWriter;
23+
import java.time.Duration;
2324
import java.util.ArrayList;
2425
import java.util.List;
2526
import java.util.function.Consumer;
@@ -262,7 +263,7 @@ void plainWarApp() throws Exception {
262263
writeServletInitializerClass();
263264
String imageName = "paketo-integration/" + this.gradleBuild.getProjectDir().getName();
264265
ImageReference imageReference = ImageReference.of(ImageName.of(imageName));
265-
BuildResult result = buildImage(imageName);
266+
BuildResult result = buildImageWithRetry(imageName);
266267
assertThat(result.task(":bootBuildImage").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
267268
try (GenericContainer<?> container = new GenericContainer<>(imageName)) {
268269
container.withExposedPorts(8080);
@@ -336,6 +337,30 @@ void nativeApp() throws Exception {
336337
}
337338
}
338339

340+
private BuildResult buildImageWithRetry(String imageName, String... arguments) {
341+
long start = System.nanoTime();
342+
while (true) {
343+
try {
344+
return buildImage(imageName, arguments);
345+
}
346+
catch (Exception ex) {
347+
if (Duration.ofNanos(System.nanoTime() - start).toMinutes() > 6) {
348+
throw ex;
349+
}
350+
sleep(500);
351+
}
352+
}
353+
}
354+
355+
private void sleep(long time) {
356+
try {
357+
Thread.sleep(time);
358+
}
359+
catch (InterruptedException ex) {
360+
Thread.currentThread().interrupt();
361+
}
362+
}
363+
339364
private BuildResult buildImage(String imageName, String... arguments) {
340365
String[] buildImageArgs = { "bootBuildImage", "--imageName=" + imageName, "--pullPolicy=IF_NOT_PRESENT" };
341366
String[] args = StringUtils.concatenateStringArrays(arguments, buildImageArgs);

0 commit comments

Comments
 (0)