use of com.google.devtools.build.skyframe.GraphTester.StringValue in project bazel by bazelbuild.
the class MemoizingEvaluatorTest method changePruningFromOtherNodeAfterParentPrunes.
@Test
public void changePruningFromOtherNodeAfterParentPrunes() throws Exception {
initializeTester();
final SkyKey leaf = GraphTester.toSkyKey("leaf");
final SkyKey other = GraphTester.toSkyKey("other");
SkyKey top = GraphTester.toSkyKey("top");
tester.set(leaf, new StringValue("leafy"));
tester.set(other, new StringValue("other"));
// When top depends on leaf and other, but always returns the same value,
final StringValue fixedTopValue = new StringValue("top");
final AtomicBoolean topEvaluated = new AtomicBoolean(false);
tester.getOrCreate(top).setBuilder(new SkyFunction() {
@Override
public SkyValue compute(SkyKey skyKey, Environment env) throws InterruptedException {
topEvaluated.set(true);
return env.getValue(other) == null || env.getValue(leaf) == null ? null : fixedTopValue;
}
@Nullable
@Override
public String extractTag(SkyKey skyKey) {
return null;
}
});
// And top is evaluated,
StringValue topValue = (StringValue) tester.evalAndGet("top");
// Then top's value is as expected,
assertEquals(fixedTopValue, topValue);
// And top was actually evaluated.
assertThat(topEvaluated.get()).isTrue();
// When leaf is changed,
tester.set(leaf, new StringValue("crunchy"));
tester.invalidate();
topEvaluated.set(false);
// And top is evaluated,
StringValue topValue2 = (StringValue) tester.evalAndGet("top");
// Then top's value is as expected,
assertEquals(fixedTopValue, topValue2);
// And top was actually evaluated.
assertThat(topEvaluated.get()).isTrue();
// When other is invalidated but not actually changed,
tester.getOrCreate(other, /*markAsModified=*/
true);
tester.invalidate();
topEvaluated.set(false);
// And top is evaluated,
StringValue topValue3 = (StringValue) tester.evalAndGet("top");
// Then top's value is as expected,
assertEquals(fixedTopValue, topValue3);
// And top was *not* actually evaluated, because change pruning cut off evaluation.
assertThat(topEvaluated.get()).isFalse();
}
use of com.google.devtools.build.skyframe.GraphTester.StringValue in project bazel by bazelbuild.
the class MemoizingEvaluatorTest method invalidationWithNothingChanged.
@Test
public void invalidationWithNothingChanged() throws Exception {
tester.set("x", new StringValue("y")).setWarning("fizzlepop");
StringValue value = (StringValue) tester.evalAndGet("x");
assertEquals("y", value.getValue());
assertContainsEvent(eventCollector, "fizzlepop");
assertEventCount(1, eventCollector);
initializeReporter();
tester.invalidate();
value = (StringValue) tester.evalAndGet("x");
assertEquals("y", value.getValue());
if (eventsStored()) {
assertContainsEvent(eventCollector, "fizzlepop");
assertEventCount(1, eventCollector);
}
}
use of com.google.devtools.build.skyframe.GraphTester.StringValue in project bazel by bazelbuild.
the class MemoizingEvaluatorTest method changedBuildAfterFailedThenSuccessfulBuild.
/**
* Regression test: error when clearing reverse deps on dirty value about to be rebuilt, because
* child values were deleted and recreated in interim, forgetting they had reverse dep on dirty
* value in the first place.
*/
@Test
public void changedBuildAfterFailedThenSuccessfulBuild() throws Exception {
initializeTester();
final SkyKey leaf = GraphTester.toSkyKey("leaf");
SkyKey top = GraphTester.toSkyKey("top");
tester.getOrCreate(top).addDependency(leaf).setComputedValue(COPY);
tester.set(leaf, new StringValue("leafy"));
StringValue topValue = (StringValue) tester.evalAndGet("top");
assertEquals("leafy", topValue.getValue());
assertThat(tester.getDirtyKeys()).isEmpty();
assertThat(tester.getDeletedKeys()).isEmpty();
failBuildAndRemoveValue(leaf);
tester.set(leaf, new StringValue("crunchy"));
tester.invalidate();
tester.eval(/*keepGoing=*/
false, leaf);
// Leaf no longer has reverse dep on top. Check that this doesn't cause problems, even if the
// top value is evaluated unconditionally.
tester.getOrCreate(top, /*markAsModified=*/
true);
tester.invalidate();
topValue = (StringValue) tester.evalAndGet("top");
assertEquals("crunchy", topValue.getValue());
}
use of com.google.devtools.build.skyframe.GraphTester.StringValue in project bazel by bazelbuild.
the class MemoizingEvaluatorTest method cleanReverseDepFromDirtyNodeNotInBuild.
@Test
public void cleanReverseDepFromDirtyNodeNotInBuild() throws Exception {
final SkyKey topKey = GraphTester.skyKey("top");
SkyKey inactiveKey = GraphTester.skyKey("inactive");
final Thread mainThread = Thread.currentThread();
final AtomicBoolean shouldInterrupt = new AtomicBoolean(false);
injectGraphListenerForTesting(new Listener() {
@Override
public void accept(SkyKey key, EventType type, Order order, Object context) {
if (shouldInterrupt.get() && key.equals(topKey) && type == EventType.IS_READY && order == Order.BEFORE) {
mainThread.interrupt();
shouldInterrupt.set(false);
try {
// Make sure threadpool propagates interrupt.
Thread.sleep(TestUtils.WAIT_TIMEOUT_MILLISECONDS);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
}
}, /*deterministic=*/
false);
// When top depends on inactive,
tester.getOrCreate(topKey).addDependency(inactiveKey).setComputedValue(COPY);
StringValue val = new StringValue("inactive");
// And inactive is constant,
tester.set(inactiveKey, val);
// Then top evaluates normally.
assertThat(tester.evalAndGet(/*keepGoing=*/
true, topKey)).isEqualTo(val);
// When evaluation will be interrupted as soon as top starts evaluating,
shouldInterrupt.set(true);
// And inactive is dirty,
tester.getOrCreate(inactiveKey, /*markAsModified=*/
true);
// And so is top,
tester.getOrCreate(topKey, /*markAsModified=*/
true);
tester.invalidate();
try {
// Then evaluation is interrupted,
tester.eval(/*keepGoing=*/
false, topKey);
fail();
} catch (InterruptedException e) {
// Expected.
}
// But inactive is still present,
assertThat(tester.driver.getEntryForTesting(inactiveKey)).isNotNull();
// And still dirty,
assertThat(tester.driver.getEntryForTesting(inactiveKey).isDirty()).isTrue();
// And re-evaluates successfully,
assertThat(tester.evalAndGet(/*keepGoing=*/
true, inactiveKey)).isEqualTo(val);
// But top is gone from the graph,
assertThat(tester.driver.getEntryForTesting(topKey)).isNull();
// And we can successfully invalidate and re-evaluate inactive again.
tester.getOrCreate(inactiveKey, /*markAsModified=*/
true);
tester.invalidate();
assertThat(tester.evalAndGet(/*keepGoing=*/
true, inactiveKey)).isEqualTo(val);
}
use of com.google.devtools.build.skyframe.GraphTester.StringValue in project bazel by bazelbuild.
the class MemoizingEvaluatorTest method passThenFailToBuildAlternateOrder.
@Test
public void passThenFailToBuildAlternateOrder() throws Exception {
CountDownLatch blocker = new CountDownLatch(1);
SkyKey successKey = GraphTester.toSkyKey("success");
tester.getOrCreate(successKey).setBuilder(new ChainedFunction(/*notifyStart=*/
null, /*waitToFinish=*/
null, /*notifyFinish=*/
blocker, /*waitForException=*/
false, new StringValue("yippee"), /*deps=*/
ImmutableList.<SkyKey>of()));
SkyKey slowFailKey = GraphTester.toSkyKey("slow_then_fail");
tester.getOrCreate(slowFailKey).setBuilder(new ChainedFunction(/*notifyStart=*/
null, /*waitToFinish=*/
blocker, /*notifyFinish=*/
null, /*waitForException=*/
false, /*value=*/
null, /*deps=*/
ImmutableList.<SkyKey>of()));
EvaluationResult<StringValue> result = tester.eval(/*keepGoing=*/
false, slowFailKey, successKey);
assertThat(result.getError().getRootCauses()).containsExactly(slowFailKey);
assertThat(result.values()).containsExactly(new StringValue("yippee"));
}
Aggregations