Add explicit unit test for the case where a SkyFunction doesn't request the same deps on each restart.
Bazel actually has several SkyFunctions that do this, albeit in a much less arbitrary way than SkyFunction in the test case does.
RELNOTES: None
@@ -2585,6 +2585,60 @@ public class ParallelEvaluatorTest {
assertThat(result.errorMap()).doesNotContainKey(rogueKey);
}
+ // Explicit test that we tolerate a SkyFunction that declares different [sequences of] deps each
+ // restart. Such behavior from a SkyFunction isn't desired, but Bazel-on-Skyframe does indeed do
+ // this.
+ @Test
+ public void declaresDifferentDepsAfterRestart() throws Exception {
+ graph = new DeterministicHelper.DeterministicProcessableGraph(new InMemoryGraphImpl());
+ tester = new GraphTester();
+ SkyKey grandChild1Key = GraphTester.toSkyKey("grandChild1");
+ tester.getOrCreate(grandChild1Key).setConstantValue(new StringValue("grandChild1"));
+ SkyKey child1Key = GraphTester.toSkyKey("child1");
+ tester
+ .getOrCreate(child1Key)
+ .addDependency(grandChild1Key)
+ .setConstantValue(new StringValue("child1"));
+ SkyKey grandChild2Key = GraphTester.toSkyKey("grandChild2");
+ tester.getOrCreate(grandChild2Key).setConstantValue(new StringValue("grandChild2"));
+ SkyKey child2Key = GraphTester.toSkyKey("child2");
+ tester.getOrCreate(child2Key).setConstantValue(new StringValue("child2"));
+ SkyKey parentKey = GraphTester.toSkyKey("parent");
+ AtomicInteger numComputes = new AtomicInteger(0);
+ tester
+ .getOrCreate(parentKey)
+ .setBuilder(
+ new SkyFunction() {
+ @Override
+ public SkyValue compute(SkyKey skyKey, Environment env) throws InterruptedException {
+ switch (numComputes.incrementAndGet()) {
+ case 1:
+ env.getValue(child1Key);
+ Preconditions.checkState(env.valuesMissing());
+ return null;
+ case 2:
+ env.getValue(child2Key);
+ Preconditions.checkState(env.valuesMissing());
+ return null;
+ case 3:
+ return new StringValue("the third time's the charm!");
+ default:
+ throw new IllegalStateException();
+ }
+ }
+
+ @Override
+ public String extractTag(SkyKey skyKey) {
+ return null;
+ }
+ });
+ EvaluationResult<StringValue> result = eval(/*keepGoing=*/ false, ImmutableList.of(parentKey));
+ assertThatEvaluationResult(result).hasNoError();
+ assertThatEvaluationResult(result)
+ .hasEntryThat(parentKey)
+ .isEqualTo(new StringValue("the third time's the charm!"));
+ }
+
private void runUnhandledTransitiveErrors(boolean keepGoing,
final boolean explicitlyPropagateError) throws Exception {
graph = new DeterministicHelper.DeterministicProcessableGraph(new InMemoryGraphImpl());
