Skip to content

Commit 3607554

Browse files
committed
8287352: DockerTestUtils::execute shows incorrect elapsed time
Backport-of: ec97da93c1d5bfcb80c19c15169f41926e59517b
1 parent f3b9244 commit 3607554

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

test/lib/jdk/test/lib/containers/docker/DockerTestUtils.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,6 @@ public static OutputAnalyzer execute(List<String> command) throws Exception {
275275
* @throws Exception
276276
*/
277277
public static OutputAnalyzer execute(String... command) throws Exception {
278-
279278
ProcessBuilder pb = new ProcessBuilder(command);
280279
System.out.println("[COMMAND]\n" + Utils.getCommandLine(pb));
281280

@@ -284,14 +283,19 @@ public static OutputAnalyzer execute(String... command) throws Exception {
284283
long pid = p.pid();
285284
OutputAnalyzer output = new OutputAnalyzer(p);
286285

287-
String stdoutLogFile = String.format("docker-stdout-%d.log", pid);
286+
int max = MAX_LINES_TO_COPY_FOR_CHILD_STDOUT;
287+
String stdout = output.getStdout();
288+
String stdoutLimited = limitLines(stdout, max);
288289
System.out.println("[ELAPSED: " + (System.currentTimeMillis() - started) + " ms]");
289290
System.out.println("[STDERR]\n" + output.getStderr());
290-
System.out.println("[STDOUT]\n" +
291-
trimLines(output.getStdout(),MAX_LINES_TO_COPY_FOR_CHILD_STDOUT));
292-
System.out.printf("Child process STDOUT is trimmed to %d lines \n",
293-
MAX_LINES_TO_COPY_FOR_CHILD_STDOUT);
294-
writeOutputToFile(output.getStdout(), stdoutLogFile);
291+
System.out.println("[STDOUT]\n" + stdoutLimited);
292+
if (stdout != stdoutLimited) {
293+
System.out.printf("Child process STDOUT is limited to %d lines\n",
294+
max);
295+
}
296+
297+
String stdoutLogFile = String.format("docker-stdout-%d.log", pid);
298+
writeOutputToFile(stdout, stdoutLogFile);
295299
System.out.println("Full child process STDOUT was saved to " + stdoutLogFile);
296300

297301
return output;
@@ -305,7 +309,7 @@ private static void writeOutputToFile(String output, String fileName) throws Exc
305309
}
306310

307311

308-
private static String trimLines(String buffer, int nrOfLines) {
312+
private static String limitLines(String buffer, int nrOfLines) {
309313
List<String> l = Arrays.asList(buffer.split("\\R"));
310314
if (l.size() < nrOfLines) {
311315
return buffer;

0 commit comments

Comments
 (0)