Search in sources :

Example 21 with Environment

use of com.google.devtools.build.skyframe.SkyFunction.Environment in project bazel by bazelbuild.

the class MemoizingEvaluatorTest method crashAfterInterruptCrashes.

@Test
public void crashAfterInterruptCrashes() throws Exception {
    SkyKey failKey = GraphTester.skyKey("fail");
    SkyKey badInterruptkey = GraphTester.skyKey("bad-interrupt");
    // Given a SkyFunction implementation which is improperly coded to throw a runtime exception
    // when it is interrupted,
    final CountDownLatch badInterruptStarted = new CountDownLatch(1);
    tester.getOrCreate(badInterruptkey).setBuilder(new SkyFunction() {

        @Nullable
        @Override
        public SkyValue compute(SkyKey skyKey, Environment env) {
            badInterruptStarted.countDown();
            try {
                Thread.sleep(TestUtils.WAIT_TIMEOUT_MILLISECONDS);
                throw new AssertionError("Shouldn't have slept so long");
            } catch (InterruptedException e) {
                throw new RuntimeException("I don't like being woken up!");
            }
        }

        @Nullable
        @Override
        public String extractTag(SkyKey skyKey) {
            return null;
        }
    });
    // And another SkyFunction that waits for the first to start, and then throws,
    tester.getOrCreate(failKey).setBuilder(new ChainedFunction(null, badInterruptStarted, null, /*waitForException=*/
    false, null, ImmutableList.<SkyKey>of()));
    try {
        // When it is interrupted during evaluation (here, caused by the failure of the throwing
        // SkyFunction during a no-keep-going evaluation),
        EvaluationResult<StringValue> unexpectedResult = tester.eval(/*keepGoing=*/
        false, badInterruptkey, failKey);
        fail(unexpectedResult.toString());
    } catch (RuntimeException e) {
        // Then the Evaluator#evaluate call throws a RuntimeException e where e.getCause() is the
        // RuntimeException thrown by that SkyFunction.
        assertThat(e.getCause()).hasMessage("I don't like being woken up!");
    }
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) Environment(com.google.devtools.build.skyframe.SkyFunction.Environment) NotComparableStringValue(com.google.devtools.build.skyframe.GraphTester.NotComparableStringValue) StringValue(com.google.devtools.build.skyframe.GraphTester.StringValue) Nullable(javax.annotation.Nullable) Test(org.junit.Test)

Aggregations

Environment (com.google.devtools.build.skyframe.SkyFunction.Environment)21 NotComparableStringValue (com.google.devtools.build.skyframe.GraphTester.NotComparableStringValue)19 StringValue (com.google.devtools.build.skyframe.GraphTester.StringValue)19 Test (org.junit.Test)19 Nullable (javax.annotation.Nullable)9 CountDownLatch (java.util.concurrent.CountDownLatch)8 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)6 EventType (com.google.devtools.build.skyframe.NotifyingHelper.EventType)5 Listener (com.google.devtools.build.skyframe.NotifyingHelper.Listener)5 Order (com.google.devtools.build.skyframe.NotifyingHelper.Order)5 ImmutableMap (com.google.common.collect.ImmutableMap)2 TestThread (com.google.devtools.build.lib.testutil.TestThread)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 ActionExecutionContext (com.google.devtools.build.lib.actions.ActionExecutionContext)1 ActionExecutionException (com.google.devtools.build.lib.actions.ActionExecutionException)1 Artifact (com.google.devtools.build.lib.actions.Artifact)1 ErrorInfoSubjectFactory.assertThatErrorInfo (com.google.devtools.build.skyframe.ErrorInfoSubjectFactory.assertThatErrorInfo)1 ValueComputer (com.google.devtools.build.skyframe.GraphTester.ValueComputer)1