Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8321718

ProcessTools.executeProcess calls waitFor before logging

XMLWordPrintable

    • gc
    • b04

        There is some logging printed when tests spawns processes. This logging is triggered from calls to OutputAnalyzer, when it delegates calls to LazyOutputBuffer.

        If we write code like this:
        ```
        ProcessBuilder pb = ProcessTools.createTestJavaProcessBuilder(...);
        OutputAnalyzer output = new OutputAnalyzer(pb.start());
        int exitValue = output.getExitValue();
        ```

        We get the following logging:
        [timestamp0] "Gathering output for process <pid>
        [timestamp1] Waiting for completion for process <pid>
        [timestamp2] Waiting for completion finished for process <pid>

        The first line comes from the OutputAnalyzer constructor and the two other lines comes from the getExitValue() call, which calls logs the above messages around the call to waitFor.

        If instead write the code above as:
        ```
        ProcessBuilder pb = ProcessTools.createTestJavaProcessBuilder(...);
        OutputAnalyzer output = ProcessTools.executeProcess(pb);
        int exitValue = output.getExitValue();
        ```

        We get the same logging, but timestamp1 and timestamp2 is almost the same. This happens because there's an extra call to waitFor inside executeProcess, but that waitFor does not have the "wait for" logging. So, instead we get the logging for the no-op waitFor inside getExitValue().

              stefank Stefan Karlsson
              stefank Stefan Karlsson
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Created:
                Updated:
                Resolved: