Skip to content

Commit

Permalink
Improve diagnostics when run does not produce expected logging
Browse files Browse the repository at this point in the history
  • Loading branch information
wilkinsona committed Sep 29, 2022
1 parent 84a25c7 commit 8a93abf
Showing 1 changed file with 8 additions and 2 deletions.
Expand Up @@ -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;
Expand Down Expand Up @@ -133,8 +134,10 @@ void runApplication() throws IOException {
private void awaitLogging(Process process) {
long end = System.currentTimeMillis() + 30000;
String expectedLogging = this.expectedLogging.get();
List<String> outputLines = Collections.emptyList();
while (System.currentTimeMillis() < end) {
for (String line : outputLines()) {
outputLines = outputLines();
for (String line : outputLines) {
if (line.contains(expectedLogging)) {
return;
}
Expand All @@ -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<String> outputLines() {
Expand Down

0 comments on commit 8a93abf

Please sign in to comment.