Retry on failed plainWar test
Add retry logic for plainWar in an attempt to deal with flaky Tomcat downloads.
This commit is contained in:
parent
a20cc3d4e6
commit
7d1cc78d6b
|
|
@ -20,6 +20,7 @@ import java.io.File;
|
|||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.time.Duration;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
|
@ -262,7 +263,7 @@ class PaketoBuilderTests {
|
|||
writeServletInitializerClass();
|
||||
String imageName = "paketo-integration/" + this.gradleBuild.getProjectDir().getName();
|
||||
ImageReference imageReference = ImageReference.of(ImageName.of(imageName));
|
||||
BuildResult result = buildImage(imageName);
|
||||
BuildResult result = buildImageWithRetry(imageName);
|
||||
assertThat(result.task(":bootBuildImage").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
||||
try (GenericContainer<?> container = new GenericContainer<>(imageName)) {
|
||||
container.withExposedPorts(8080);
|
||||
|
|
@ -336,6 +337,30 @@ class PaketoBuilderTests {
|
|||
}
|
||||
}
|
||||
|
||||
private BuildResult buildImageWithRetry(String imageName, String... arguments) {
|
||||
long start = System.nanoTime();
|
||||
while (true) {
|
||||
try {
|
||||
return buildImage(imageName, arguments);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
if (Duration.ofNanos(System.nanoTime() - start).toMinutes() > 6) {
|
||||
throw ex;
|
||||
}
|
||||
sleep(500);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void sleep(long time) {
|
||||
try {
|
||||
Thread.sleep(time);
|
||||
}
|
||||
catch (InterruptedException ex) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
|
||||
private BuildResult buildImage(String imageName, String... arguments) {
|
||||
String[] buildImageArgs = { "bootBuildImage", "--imageName=" + imageName, "--pullPolicy=IF_NOT_PRESENT" };
|
||||
String[] args = StringUtils.concatenateStringArrays(arguments, buildImageArgs);
|
||||
|
|
|
|||
Loading…
Reference in New Issue