From 3e35fd480fdb35cfb223c232933998016316872c Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Fri, 14 Aug 2020 15:34:41 +0100 Subject: [PATCH] Wait longer for server port and improve diagnostics on timeout See gh-22909 --- .../boot/devtools/tests/ApplicationState.java | 13 +++++++++---- .../boot/devtools/tests/JvmLauncher.java | 7 +++++++ .../boot/devtools/tests/LaunchedApplication.java | 7 +++++++ .../devtools/tests/RemoteApplicationLauncher.java | 2 +- 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/spring-boot-project/spring-boot-devtools/src/intTest/java/org/springframework/boot/devtools/tests/ApplicationState.java b/spring-boot-project/spring-boot-devtools/src/intTest/java/org/springframework/boot/devtools/tests/ApplicationState.java index 95f5c7aea1..d063352aaf 100644 --- a/spring-boot-project/spring-boot-devtools/src/intTest/java/org/springframework/boot/devtools/tests/ApplicationState.java +++ b/spring-boot-project/spring-boot-devtools/src/intTest/java/org/springframework/boot/devtools/tests/ApplicationState.java @@ -17,6 +17,7 @@ package org.springframework.boot.devtools.tests; import java.io.File; +import java.time.Instant; import org.springframework.boot.devtools.tests.JvmLauncher.LaunchedJvm; @@ -27,6 +28,8 @@ import org.springframework.boot.devtools.tests.JvmLauncher.LaunchedJvm; */ final class ApplicationState { + private final Instant launchTime; + private final Integer serverPort; private final FileContents out; @@ -34,17 +37,18 @@ final class ApplicationState { private final FileContents err; ApplicationState(File serverPortFile, LaunchedJvm jvm) { - this(serverPortFile, jvm.getStandardOut(), jvm.getStandardError()); + this(serverPortFile, jvm.getStandardOut(), jvm.getStandardError(), jvm.getLaunchTime()); } 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.out = new FileContents(out); this.err = new FileContents(err); + this.launchTime = launchTime; } boolean hasServerPort() { @@ -57,7 +61,8 @@ final class ApplicationState { @Override 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); } } diff --git a/spring-boot-project/spring-boot-devtools/src/intTest/java/org/springframework/boot/devtools/tests/JvmLauncher.java b/spring-boot-project/spring-boot-devtools/src/intTest/java/org/springframework/boot/devtools/tests/JvmLauncher.java index 43caf1bc04..757ed11f87 100644 --- a/spring-boot-project/spring-boot-devtools/src/intTest/java/org/springframework/boot/devtools/tests/JvmLauncher.java +++ b/spring-boot-project/spring-boot-devtools/src/intTest/java/org/springframework/boot/devtools/tests/JvmLauncher.java @@ -18,6 +18,7 @@ package org.springframework.boot.devtools.tests; import java.io.File; import java.io.IOException; +import java.time.Instant; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -66,6 +67,8 @@ class JvmLauncher implements BeforeTestExecutionCallback { private final Process process; + private final Instant launchTime = Instant.now(); + private final File standardOut; private final File standardError; @@ -80,6 +83,10 @@ class JvmLauncher implements BeforeTestExecutionCallback { return this.process; } + Instant getLaunchTime() { + return this.launchTime; + } + File getStandardOut() { return this.standardOut; } diff --git a/spring-boot-project/spring-boot-devtools/src/intTest/java/org/springframework/boot/devtools/tests/LaunchedApplication.java b/spring-boot-project/spring-boot-devtools/src/intTest/java/org/springframework/boot/devtools/tests/LaunchedApplication.java index 9838f1dcea..f46272cc29 100644 --- a/spring-boot-project/spring-boot-devtools/src/intTest/java/org/springframework/boot/devtools/tests/LaunchedApplication.java +++ b/spring-boot-project/spring-boot-devtools/src/intTest/java/org/springframework/boot/devtools/tests/LaunchedApplication.java @@ -17,6 +17,7 @@ package org.springframework.boot.devtools.tests; import java.io.File; +import java.time.Instant; import java.util.function.BiFunction; /** @@ -36,6 +37,8 @@ class LaunchedApplication { private Process remoteProcess; + private final Instant launchTime = Instant.now(); + private final BiFunction remoteProcessRestarter; LaunchedApplication(File classesDirectory, File standardOut, File standardError, Process localProcess, @@ -79,4 +82,8 @@ class LaunchedApplication { return this.classesDirectory; } + Instant getLaunchTime() { + return this.launchTime; + } + } diff --git a/spring-boot-project/spring-boot-devtools/src/intTest/java/org/springframework/boot/devtools/tests/RemoteApplicationLauncher.java b/spring-boot-project/spring-boot-devtools/src/intTest/java/org/springframework/boot/devtools/tests/RemoteApplicationLauncher.java index a828d584f1..5f6692c624 100644 --- a/spring-boot-project/spring-boot-devtools/src/intTest/java/org/springframework/boot/devtools/tests/RemoteApplicationLauncher.java +++ b/spring-boot-project/spring-boot-devtools/src/intTest/java/org/springframework/boot/devtools/tests/RemoteApplicationLauncher.java @@ -101,7 +101,7 @@ abstract class RemoteApplicationLauncher extends AbstractApplicationLauncher { } 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) .getServerPort(); }