From 2b1bb2f18f741644b72007fba7011817acd300e5 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Wed, 12 Aug 2020 13:15:36 +0100 Subject: [PATCH] Improve diagnostics when remote application does not start as expected See gh-22909 --- .../tests/RemoteApplicationLauncher.java | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) 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 2a6864c35f..a828d584f1 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 @@ -24,6 +24,7 @@ import java.util.List; import java.util.function.BiFunction; import org.awaitility.Awaitility; +import org.awaitility.core.ConditionTimeoutException; import org.springframework.boot.devtools.RemoteSpringApplication; import org.springframework.boot.devtools.tests.JvmLauncher.LaunchedJvm; @@ -77,7 +78,7 @@ abstract class RemoteApplicationLauncher extends AbstractApplicationLauncher { createRemoteSpringApplicationClassPath(classesDirectory), RemoteSpringApplication.class.getName(), "--spring.devtools.remote.secret=secret", "http://localhost:" + port); - awaitRemoteSpringApplication(remoteSpringApplicationJvm.getStandardOut()); + awaitRemoteSpringApplication(remoteSpringApplicationJvm); return remoteSpringApplicationJvm.getProcess(); } catch (Exception ex) { @@ -105,10 +106,22 @@ abstract class RemoteApplicationLauncher extends AbstractApplicationLauncher { .getServerPort(); } - private void awaitRemoteSpringApplication(File standardOut) throws Exception { - FileContents contents = new FileContents(standardOut); - Awaitility.waitAtMost(Duration.ofSeconds(30)).until(contents::get, - containsString("Started RemoteSpringApplication")); + private void awaitRemoteSpringApplication(LaunchedJvm launchedJvm) throws Exception { + FileContents contents = new FileContents(launchedJvm.getStandardOut()); + try { + Awaitility.waitAtMost(Duration.ofSeconds(30)).until(contents::get, + containsString("Started RemoteSpringApplication")); + } + catch (ConditionTimeoutException ex) { + if (!launchedJvm.getProcess().isAlive()) { + throw new IllegalStateException( + "Process exited with status " + launchedJvm.getProcess().exitValue() + + " before producing expected standard output.\n\nStandard output:\n\n" + contents.get() + + "\n\nStandard error:\n\n" + new FileContents(launchedJvm.getStandardError()).get(), + ex); + } + throw ex; + } } }