diff options
author | janakr <janakr@google.com> | 2017-11-21 05:45:25 -0800 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2017-11-21 05:47:21 -0800 |
commit | 34d02ef1a47cdb7847fdd12e96d7532dc7e0d7df (patch) | |
tree | f75cf9c6dded0dcb065dd165cc7c35605a5cafce /src | |
parent | 9bb93ee8c0edae911f9e2adeaca8aebd406788b6 (diff) |
Clear interrupted bit in thread when throwing an interrupted exception that came from an AbstractParallelEvaluator evaluation. It's against the standard Java contract to throw but still have the thread's interrupted bit set.
Also get rid of some unnecessary initializeTester() calls in MemoizingEvaluatorTest: we already call it via a @Before annotation.
PiperOrigin-RevId: 176496034
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/com/google/devtools/build/skyframe/AbstractParallelEvaluator.java | 3 | ||||
-rw-r--r-- | src/test/java/com/google/devtools/build/skyframe/MemoizingEvaluatorTest.java | 16 |
2 files changed, 15 insertions, 4 deletions
diff --git a/src/main/java/com/google/devtools/build/skyframe/AbstractParallelEvaluator.java b/src/main/java/com/google/devtools/build/skyframe/AbstractParallelEvaluator.java index 9884043170..8d1fab52b0 100644 --- a/src/main/java/com/google/devtools/build/skyframe/AbstractParallelEvaluator.java +++ b/src/main/java/com/google/devtools/build/skyframe/AbstractParallelEvaluator.java @@ -564,8 +564,9 @@ public abstract class AbstractParallelEvaluator { } void propagateInterruption(SchedulerException e) throws InterruptedException { + boolean mustThrowInterrupt = Thread.interrupted(); Throwables.propagateIfPossible(e.getCause(), InterruptedException.class); - if (Thread.interrupted()) { + if (mustThrowInterrupt) { // As per the contract of AbstractQueueVisitor#work, if an unchecked exception is thrown and // the build is interrupted, the thrown exception is what will be rethrown. Since the user // presumably wanted to interrupt the build, we ignore the thrown SchedulerException (which diff --git a/src/test/java/com/google/devtools/build/skyframe/MemoizingEvaluatorTest.java b/src/test/java/com/google/devtools/build/skyframe/MemoizingEvaluatorTest.java index 061357af77..f82719dfaf 100644 --- a/src/test/java/com/google/devtools/build/skyframe/MemoizingEvaluatorTest.java +++ b/src/test/java/com/google/devtools/build/skyframe/MemoizingEvaluatorTest.java @@ -241,6 +241,19 @@ public class MemoizingEvaluatorTest { } @Test + public void interruptBitCleared() throws Exception { + SkyKey interruptKey = GraphTester.skyKey("interrupt"); + tester.getOrCreate(interruptKey).setBuilder(INTERRUPT_BUILDER); + try { + tester.eval(/*keepGoing=*/ true, interruptKey); + fail("Expected interrupt"); + } catch (InterruptedException e) { + // Expected. + } + assertThat(Thread.interrupted()).isFalse(); + } + + @Test public void crashAfterInterruptCrashes() throws Exception { SkyKey failKey = GraphTester.skyKey("fail"); SkyKey badInterruptkey = GraphTester.skyKey("bad-interrupt"); @@ -1736,7 +1749,6 @@ public class MemoizingEvaluatorTest { @Test public void continueWithErrorDepTurnedGood() throws Exception { - initializeTester(); SkyKey errorKey = GraphTester.toSkyKey("my_error_value"); tester.getOrCreate(errorKey).setHasError(true); tester.set("after", new StringValue("after")); @@ -2664,7 +2676,6 @@ public class MemoizingEvaluatorTest { @Test public void changePruning() throws Exception { - initializeTester(); SkyKey leaf = GraphTester.toSkyKey("leaf"); SkyKey mid = GraphTester.toSkyKey("mid"); SkyKey top = GraphTester.toSkyKey("top"); @@ -2722,7 +2733,6 @@ public class MemoizingEvaluatorTest { @Test public void changePruningAfterParentPrunes() throws Exception { - initializeTester(); final SkyKey leaf = GraphTester.toSkyKey("leaf"); SkyKey top = GraphTester.toSkyKey("top"); tester.set(leaf, new StringValue("leafy")); |