Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix builds hanging if server cannot start #812

Merged
merged 1 commit into from
Jan 10, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,10 @@ public class ServerUtils {
private static final String FLAT_JAR = "flat.jar";

// See io.micronaut.testresources.testcontainers.DockerSupport.TIMEOUT
private static final String DOCKER_CHECK_TIMEOUT_SECONDS_ENV = "TEST_RESOURCES_DOCKER_CHECK_TIMEOUT_SECONDS";
private static final String DOCKER_CHECK_TIMEOUT_SECONDS_PROPERTY = "docker.check.timeout.seconds";
private static final String DOCKER_CHECK_TIMEOUT_SECONDS_ENV =
"TEST_RESOURCES_DOCKER_CHECK_TIMEOUT_SECONDS";
private static final String DOCKER_CHECK_TIMEOUT_SECONDS_PROPERTY =
"docker.check.timeout.seconds";

/**
* Writes the server settings in an output directory.
Expand Down Expand Up @@ -335,16 +337,24 @@ private static void startAndWait(ServerFactory serverFactory,
waitForServerToBeAvailable(serverFactory, explicitPort, portFilePath);
}

private static void waitForServerToBeAvailable(ServerFactory serverFactory, Integer explicitPort,
Path portFilePath) {
private static void waitForServerToBeAvailable(ServerFactory serverFactory,
Integer explicitPort,
Path portFilePath) {
Integer port = explicitPort;
if (explicitPort == null) {
while (!Files.exists(portFilePath)) {
int retries = 4;
long dur = STARTUP_TIME_WAIT_MS;
while (--retries > 0 && !Files.exists(portFilePath)) {
try {
serverFactory.waitFor(Duration.of(STARTUP_TIME_WAIT_MS, ChronoUnit.MILLIS));
serverFactory.waitFor(Duration.of(dur, ChronoUnit.MILLIS));
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
break;
}
dur *= 2;
}
if (!Files.exists(portFilePath)) {
throw new IllegalStateException("Port file not created. Server probably failed to start.");
}
try {
port = Integer.parseInt(Files.readString(portFilePath));
Expand Down
Loading