|
20 | 20 | import java.io.FileWriter; |
21 | 21 | import java.io.IOException; |
22 | 22 | import java.io.PrintWriter; |
| 23 | +import java.time.Duration; |
23 | 24 | import java.util.ArrayList; |
24 | 25 | import java.util.List; |
25 | 26 | import java.util.function.Consumer; |
@@ -267,7 +268,7 @@ void plainWarApp() throws Exception { |
267 | 268 | writeServletInitializerClass(); |
268 | 269 | String imageName = "paketo-integration/" + this.gradleBuild.getProjectDir().getName(); |
269 | 270 | ImageReference imageReference = ImageReference.of(ImageName.of(imageName)); |
270 | | - BuildResult result = buildImage(imageName); |
| 271 | + BuildResult result = buildImageWithRetry(imageName); |
271 | 272 | assertThat(result.task(":bootBuildImage").getOutcome()).isEqualTo(TaskOutcome.SUCCESS); |
272 | 273 | assertThat(result.getOutput()).contains("Running creator"); |
273 | 274 | try (GenericContainer<?> container = new GenericContainer<>(imageName)) { |
@@ -378,6 +379,30 @@ void classDataSharingApp() throws Exception { |
378 | 379 | } |
379 | 380 | } |
380 | 381 |
|
| 382 | + private BuildResult buildImageWithRetry(String imageName, String... arguments) { |
| 383 | + long start = System.nanoTime(); |
| 384 | + while (true) { |
| 385 | + try { |
| 386 | + return buildImage(imageName, arguments); |
| 387 | + } |
| 388 | + catch (Exception ex) { |
| 389 | + if (Duration.ofNanos(System.nanoTime() - start).toMinutes() > 6) { |
| 390 | + throw ex; |
| 391 | + } |
| 392 | + sleep(500); |
| 393 | + } |
| 394 | + } |
| 395 | + } |
| 396 | + |
| 397 | + private void sleep(long time) { |
| 398 | + try { |
| 399 | + Thread.sleep(time); |
| 400 | + } |
| 401 | + catch (InterruptedException ex) { |
| 402 | + Thread.currentThread().interrupt(); |
| 403 | + } |
| 404 | + } |
| 405 | + |
381 | 406 | private BuildResult buildImage(String imageName, String... arguments) { |
382 | 407 | List<String> args = new ArrayList<>(List.of(arguments)); |
383 | 408 | args.add("bootBuildImage"); |
|
0 commit comments