commit 3c21b52c001c2b150c68652bd00576c330bf6864 Author: Mike Solomon Date: Fri May 31 13:44:01 2019 -0700 Write output from JUnit ConsoleRunner when process is terminated (#7799) ### Problem Pants enforces test timeouts for JVM JUnit tests by terminating the JVM process (usually sending SIGINT). When this happens today, test output is not consistently written out. In particular, XML output from AntJunitXmlReportListener will not be written. Unfortunately, this means test tooling that relies on this XML cannot accurately report test results when the global timeout (usually set with --test-junit-timeout-default) is reached. ### Solution Add a JVM shutdown hook to write out test results on JVM termination. ### Result JUnit test results are available even when Pants times out on a given test run. ### Notes This branch also makes the following changes in support of this: * Adds close() to the StreamSource interface to ensure we can close output streams before using their values, and uses it * Modifies ConsoleRunnerImpl to improve testability (as might be expected, it's tricky to test behavior triggered on SIGINT) * Generalizes and simplifies ShutdownListener so that it: - Supports parallel test execution - Tracks result state across the entire lifecycle - Delegates its work instead of extending ConsoleListener * Adjusts the counting of tests in AntJunitXmlReportListener to be accurate in the face of abnormal termination .../junit/impl/AntJunitXmlReportListener.java | 8 +- .../tools/junit/impl/ConsoleRunnerImpl.java | 129 ++++++++++++++++++--- .../tools/junit/impl/ShutdownListener.java | 80 ++++++++----- .../pantsbuild/tools/junit/impl/StreamSource.java | 8 ++ 4 files changed, 175 insertions(+), 50 deletions(-)