From 2a522d07a56dddff47f3711b3b52bd6f5e7064ba Mon Sep 17 00:00:00 2001 From: Henry Coles Date: Mon, 4 Jul 2022 14:50:19 +0100 Subject: [PATCH] mitigation for process hangs Possible mitigation for #1047 --- .../mutationtest/execute/MutationTestMinion.java | 13 ++++++++++++- .../execute/MutationTestMinionTest.java | 3 ++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/pitest/src/main/java/org/pitest/mutationtest/execute/MutationTestMinion.java b/pitest/src/main/java/org/pitest/mutationtest/execute/MutationTestMinion.java index 8352f5979..b490953a9 100644 --- a/pitest/src/main/java/org/pitest/mutationtest/execute/MutationTestMinion.java +++ b/pitest/src/main/java/org/pitest/mutationtest/execute/MutationTestMinion.java @@ -100,7 +100,7 @@ public void run() { new TimeOutDecoratedTestSource(paramsFromParent.timeoutStrategy, tests, this.reporter)); - this.reporter.done(ExitCode.OK); + repeatedlySendDoneSignal(); } catch (final Throwable ex) { ex.printStackTrace(System.out); LOG.log(Level.WARNING, "Error during mutation test", ex); @@ -109,6 +109,17 @@ public void run() { } + private void repeatedlySendDoneSignal() throws InterruptedException { + // there have been reports of the done signal getting lost, causing the main process + // to hang. The root cause of this issue has not been found, this attempts to mitigate it + // by resending the signal. We don't want to spend too long doing this, as it is better for + // the minion to end naturally, than be killed by the main process. + for (int i = 0; i != 10; i++) { + this.reporter.done(ExitCode.OK); + Thread.sleep(100); + } + } + private void configureVerbosity(MinionArguments paramsFromParent) { Log.setVerbose(paramsFromParent.verbosity()); if (!paramsFromParent.verbosity().showMinionOutput()) { diff --git a/pitest/src/test/java/org/pitest/mutationtest/execute/MutationTestMinionTest.java b/pitest/src/test/java/org/pitest/mutationtest/execute/MutationTestMinionTest.java index 028aea62d..0e0dcfc9b 100644 --- a/pitest/src/test/java/org/pitest/mutationtest/execute/MutationTestMinionTest.java +++ b/pitest/src/test/java/org/pitest/mutationtest/execute/MutationTestMinionTest.java @@ -1,6 +1,7 @@ package org.pitest.mutationtest.execute; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.pitest.mutationtest.LocationMother.aMutationId; @@ -85,7 +86,7 @@ public void setup() { @Test public void shouldReportNoErrorWhenNoMutationsSupplied() { this.testee.run(); - verify(this.reporter).done(ExitCode.OK); + verify(this.reporter, atLeastOnce()).done(ExitCode.OK); } @Test