From 8a93abfaaa2d3a4127ad2701dc93749726e75c94 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Thu, 29 Sep 2022 12:52:02 +0100 Subject: [PATCH] Improve diagnostics when run does not produce expected logging --- .../boot/build/docs/ApplicationRunner.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/buildSrc/src/main/java/org/springframework/boot/build/docs/ApplicationRunner.java b/buildSrc/src/main/java/org/springframework/boot/build/docs/ApplicationRunner.java index b66a60edfbea..ba2f59dddecf 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/docs/ApplicationRunner.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/docs/ApplicationRunner.java @@ -21,6 +21,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -133,8 +134,10 @@ void runApplication() throws IOException { private void awaitLogging(Process process) { long end = System.currentTimeMillis() + 30000; String expectedLogging = this.expectedLogging.get(); + List outputLines = Collections.emptyList(); while (System.currentTimeMillis() < end) { - for (String line : outputLines()) { + outputLines = outputLines(); + for (String line : outputLines) { if (line.contains(expectedLogging)) { return; } @@ -143,7 +146,10 @@ private void awaitLogging(Process process) { throw new IllegalStateException("Process exited before '" + expectedLogging + "' was logged"); } } - throw new IllegalStateException("'" + expectedLogging + "' was not logged within 30 seconds"); + StringBuilder message = new StringBuilder( + "After 30 seconds '" + expectedLogging + "' had not be logged in the following output:\n\n"); + outputLines.forEach((line) -> message.append(line).append("\n")); + throw new IllegalStateException(message.toString()); } private List outputLines() {