Wait longer for server port and improve diagnostics on timeout

See gh-22909
pull/22996/head
Andy Wilkinson 4 years ago
parent d0cd445aea
commit 3e35fd480f

@ -17,6 +17,7 @@
package org.springframework.boot.devtools.tests; package org.springframework.boot.devtools.tests;
import java.io.File; import java.io.File;
import java.time.Instant;
import org.springframework.boot.devtools.tests.JvmLauncher.LaunchedJvm; import org.springframework.boot.devtools.tests.JvmLauncher.LaunchedJvm;
@ -27,6 +28,8 @@ import org.springframework.boot.devtools.tests.JvmLauncher.LaunchedJvm;
*/ */
final class ApplicationState { final class ApplicationState {
private final Instant launchTime;
private final Integer serverPort; private final Integer serverPort;
private final FileContents out; private final FileContents out;
@ -34,17 +37,18 @@ final class ApplicationState {
private final FileContents err; private final FileContents err;
ApplicationState(File serverPortFile, LaunchedJvm jvm) { ApplicationState(File serverPortFile, LaunchedJvm jvm) {
this(serverPortFile, jvm.getStandardOut(), jvm.getStandardError()); this(serverPortFile, jvm.getStandardOut(), jvm.getStandardError(), jvm.getLaunchTime());
} }
ApplicationState(File serverPortFile, LaunchedApplication application) { ApplicationState(File serverPortFile, LaunchedApplication application) {
this(serverPortFile, application.getStandardOut(), application.getStandardError()); this(serverPortFile, application.getStandardOut(), application.getStandardError(), application.getLaunchTime());
} }
private ApplicationState(File serverPortFile, File out, File err) { private ApplicationState(File serverPortFile, File out, File err, Instant launchTime) {
this.serverPort = new FileContents(serverPortFile).get(Integer::parseInt); this.serverPort = new FileContents(serverPortFile).get(Integer::parseInt);
this.out = new FileContents(out); this.out = new FileContents(out);
this.err = new FileContents(err); this.err = new FileContents(err);
this.launchTime = launchTime;
} }
boolean hasServerPort() { boolean hasServerPort() {
@ -57,7 +61,8 @@ final class ApplicationState {
@Override @Override
public String toString() { public String toString() {
return String.format("Application output:%n%s%n%s", this.out, this.err); return String.format("Application launched at %s produced output:%n%s%n%s", this.launchTime, this.out,
this.err);
} }
} }

@ -18,6 +18,7 @@ package org.springframework.boot.devtools.tests;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.time.Instant;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@ -66,6 +67,8 @@ class JvmLauncher implements BeforeTestExecutionCallback {
private final Process process; private final Process process;
private final Instant launchTime = Instant.now();
private final File standardOut; private final File standardOut;
private final File standardError; private final File standardError;
@ -80,6 +83,10 @@ class JvmLauncher implements BeforeTestExecutionCallback {
return this.process; return this.process;
} }
Instant getLaunchTime() {
return this.launchTime;
}
File getStandardOut() { File getStandardOut() {
return this.standardOut; return this.standardOut;
} }

@ -17,6 +17,7 @@
package org.springframework.boot.devtools.tests; package org.springframework.boot.devtools.tests;
import java.io.File; import java.io.File;
import java.time.Instant;
import java.util.function.BiFunction; import java.util.function.BiFunction;
/** /**
@ -36,6 +37,8 @@ class LaunchedApplication {
private Process remoteProcess; private Process remoteProcess;
private final Instant launchTime = Instant.now();
private final BiFunction<Integer, File, Process> remoteProcessRestarter; private final BiFunction<Integer, File, Process> remoteProcessRestarter;
LaunchedApplication(File classesDirectory, File standardOut, File standardError, Process localProcess, LaunchedApplication(File classesDirectory, File standardOut, File standardError, Process localProcess,
@ -79,4 +82,8 @@ class LaunchedApplication {
return this.classesDirectory; return this.classesDirectory;
} }
Instant getLaunchTime() {
return this.launchTime;
}
} }

@ -101,7 +101,7 @@ abstract class RemoteApplicationLauncher extends AbstractApplicationLauncher {
} }
private int awaitServerPort(LaunchedJvm jvm, File serverPortFile) throws Exception { private int awaitServerPort(LaunchedJvm jvm, File serverPortFile) throws Exception {
return Awaitility.waitAtMost(Duration.ofSeconds(30)) return Awaitility.waitAtMost(Duration.ofSeconds(60))
.until(() -> new ApplicationState(serverPortFile, jvm), ApplicationState::hasServerPort) .until(() -> new ApplicationState(serverPortFile, jvm), ApplicationState::hasServerPort)
.getServerPort(); .getServerPort();
} }

Loading…
Cancel
Save