-
Enhancement
-
Resolution: Fixed
-
P4
-
23
-
b04
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8330012 | 21.0.4 | Goetz Lindenmaier | P4 | Resolved | Fixed | b01 |
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().
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().
- backported by
-
JDK-8330012 ProcessTools.executeProcess calls waitFor before logging
- Resolved