8287352: DockerTestUtils::execute shows incorrect elapsed time
Reviewed-by: stuefe, mseledtsov
This commit is contained in:
parent
140419fe0e
commit
ec97da93c1
@ -269,7 +269,6 @@ public class DockerTestUtils {
|
|||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public static OutputAnalyzer execute(String... command) throws Exception {
|
public static OutputAnalyzer execute(String... command) throws Exception {
|
||||||
|
|
||||||
ProcessBuilder pb = new ProcessBuilder(command);
|
ProcessBuilder pb = new ProcessBuilder(command);
|
||||||
System.out.println("[COMMAND]\n" + Utils.getCommandLine(pb));
|
System.out.println("[COMMAND]\n" + Utils.getCommandLine(pb));
|
||||||
|
|
||||||
@ -278,14 +277,19 @@ public class DockerTestUtils {
|
|||||||
long pid = p.pid();
|
long pid = p.pid();
|
||||||
OutputAnalyzer output = new OutputAnalyzer(p);
|
OutputAnalyzer output = new OutputAnalyzer(p);
|
||||||
|
|
||||||
String stdoutLogFile = String.format("docker-stdout-%d.log", pid);
|
int max = MAX_LINES_TO_COPY_FOR_CHILD_STDOUT;
|
||||||
|
String stdout = output.getStdout();
|
||||||
|
String stdoutLimited = limitLines(stdout, max);
|
||||||
System.out.println("[ELAPSED: " + (System.currentTimeMillis() - started) + " ms]");
|
System.out.println("[ELAPSED: " + (System.currentTimeMillis() - started) + " ms]");
|
||||||
System.out.println("[STDERR]\n" + output.getStderr());
|
System.out.println("[STDERR]\n" + output.getStderr());
|
||||||
System.out.println("[STDOUT]\n" +
|
System.out.println("[STDOUT]\n" + stdoutLimited);
|
||||||
trimLines(output.getStdout(),MAX_LINES_TO_COPY_FOR_CHILD_STDOUT));
|
if (stdout != stdoutLimited) {
|
||||||
System.out.printf("Child process STDOUT is trimmed to %d lines \n",
|
System.out.printf("Child process STDOUT is limited to %d lines\n",
|
||||||
MAX_LINES_TO_COPY_FOR_CHILD_STDOUT);
|
max);
|
||||||
writeOutputToFile(output.getStdout(), stdoutLogFile);
|
}
|
||||||
|
|
||||||
|
String stdoutLogFile = String.format("docker-stdout-%d.log", pid);
|
||||||
|
writeOutputToFile(stdout, stdoutLogFile);
|
||||||
System.out.println("Full child process STDOUT was saved to " + stdoutLogFile);
|
System.out.println("Full child process STDOUT was saved to " + stdoutLogFile);
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
@ -299,7 +303,7 @@ public class DockerTestUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static String trimLines(String buffer, int nrOfLines) {
|
private static String limitLines(String buffer, int nrOfLines) {
|
||||||
List<String> l = Arrays.asList(buffer.split("\\R"));
|
List<String> l = Arrays.asList(buffer.split("\\R"));
|
||||||
if (l.size() < nrOfLines) {
|
if (l.size() < nrOfLines) {
|
||||||
return buffer;
|
return buffer;
|
||||||
|
Loading…
Reference in New Issue
Block a user