RFR: 8336332: Rework tests to avoid unrelated stderr output [v10]
Kevin Rushforth
kcr at openjdk.org
Thu Sep 18 18:42:54 UTC 2025
On Thu, 18 Sep 2025 18:04:22 GMT, Andy Goryachev <angorya at openjdk.org> wrote:
>> This PR removes unrelated `stderr` output in the headless test logs by redirecting it to an in-memory buffer. Exceptions found in the buffer can be checked against the expected list.
>>
>> In the case when any mismatch is detected, whether the type or the number of exceptions of particular type, the accumulated buffer gets dumped to `stderr` and the test fails.
>>
>> ## How To
>>
>> To redirect stderr and later check the exceptions, surround your code with
>>
>> `OutputRedirect.suppressStderr()` and either `OutputRedirect.checkStderr()` or `OutputRedirect.checkAndRestoreStderr()` (ideally, in the `finally` block).
>>
>> To simply undo redirection, without checking, call `OutputRedirect.restoreStderr()`.
>>
>> To add the check to all the tests in the file, one can call the above mentioned methods inside `@BeforeEach` and `@AfterEach`.
>>
>> ## Changes
>>
>> - added `OutputRedirect` facility
>>
>> ## Miscellaneous
>>
>> `ErrorLoggingUtiltity` name will be fixed in a followup https://bugs.openjdk.org/browse/JDK-8367995
>
> Andy Goryachev has updated the pull request incrementally with one additional commit since the last revision:
>
> review comments
tests/system/src/test/java/test/javafx/scene/Snapshot1Test.java line 244:
> 242: } finally {
> 243: OutputRedirect.checkAndRestoreStderr(ClassCastException.class);
> 244: }
This fails for me, which is not surprising since the snapshot is asynchronous. You probably want to move everything (the suppressStderr and the try/finally with the checkAndRestoreStderr) out of the runAndWait, but even that might not be sufficient without a delay after `latch.getCount()`.
-------------
PR Review Comment: https://git.openjdk.org/jfx/pull/1897#discussion_r2360686619
More information about the openjfx-dev
mailing list