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!");
}
}
Aggregations