From 56ca9e8cf1ea428bec54248833a00f7dc5d7d133 Mon Sep 17 00:00:00 2001 From: Henry Coles Date: Tue, 31 Oct 2023 10:28:55 +0000 Subject: [PATCH] recheck thread exit code before reporting doa minion --- .../java/org/pitest/coverage/execute/CoverageProcess.java | 6 ++++++ .../pitest/mutationtest/execute/MutationTestProcess.java | 8 +++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/pitest-entry/src/main/java/org/pitest/coverage/execute/CoverageProcess.java b/pitest-entry/src/main/java/org/pitest/coverage/execute/CoverageProcess.java index f5f49d7b0..22a9d863c 100644 --- a/pitest-entry/src/main/java/org/pitest/coverage/execute/CoverageProcess.java +++ b/pitest-entry/src/main/java/org/pitest/coverage/execute/CoverageProcess.java @@ -37,6 +37,12 @@ public ExitCode waitToDie() { while (!maybeExit.isPresent() && this.process.isAlive()) { maybeExit = this.crt.waitToFinish(10); } + + // Either the monitored process died, or the thread ended. + // Check the thread one last time to try and avoid reporting + // an error code if it was the process that went down first + maybeExit = this.crt.waitToFinish(10); + return maybeExit.orElse(ExitCode.MINION_DIED); } finally { this.process.destroy(); diff --git a/pitest-entry/src/main/java/org/pitest/mutationtest/execute/MutationTestProcess.java b/pitest-entry/src/main/java/org/pitest/mutationtest/execute/MutationTestProcess.java index 7d921ae63..27b0d50e2 100644 --- a/pitest-entry/src/main/java/org/pitest/mutationtest/execute/MutationTestProcess.java +++ b/pitest-entry/src/main/java/org/pitest/mutationtest/execute/MutationTestProcess.java @@ -51,7 +51,8 @@ public ExitCode waitToDie() { try { // Wait a moment to give the monitoring thread time to finish naturally. This // happens when the monitored process sends a "DONE" signal over the socket, - // the process itself should exit shortly after sending the signal + // the process itself should exit shortly after sending the signal. + // Most likely the process will still be running Optional maybeExit = this.thread.waitToFinish(5); // While the monitored process reports being alive, keep polling @@ -60,6 +61,11 @@ public ExitCode waitToDie() { maybeExit = this.thread.waitToFinish(10); } + // Either the monitored process died, or the thread ended. + // Check the thread one last time to try and avoid reporting + // an error code if it was the process that went down first + maybeExit = this.thread.waitToFinish(10); + // If the monitored thread is still live, but the process is dead // then either the process never properly started or it died // before reporting its exit