use of com.google.devtools.build.skyframe.GraphTester.StringValue in project bazel by bazelbuild.
the class MemoizingEvaluatorTest method changePruningWithEvent.
@Test
public void changePruningWithEvent() throws Exception {
initializeTester();
SkyKey parent = GraphTester.toSkyKey("parent");
SkyKey child = GraphTester.toSkyKey("child");
tester.getOrCreate(child).setConstantValue(new StringValue("child")).setWarning("bloop");
// Restart once because child isn't ready.
CountDownLatch parentEvaluated = new CountDownLatch(3);
StringValue parentVal = new StringValue("parent");
tester.getOrCreate(parent).setBuilder(new ChainedFunction(parentEvaluated, null, null, false, parentVal, ImmutableList.of(child)));
assertThat(tester.evalAndGet(/*keepGoing=*/
false, parent)).isEqualTo(parentVal);
assertThat(parentEvaluated.getCount()).isEqualTo(1);
assertContainsEvent(eventCollector, "bloop");
tester.resetPlayedEvents();
tester.getOrCreate(child, /*markAsModified=*/
true);
tester.invalidate();
assertThat(tester.evalAndGet(/*keepGoing=*/
false, parent)).isEqualTo(parentVal);
assertContainsEvent(eventCollector, "bloop");
assertThat(parentEvaluated.getCount()).isEqualTo(1);
}
use of com.google.devtools.build.skyframe.GraphTester.StringValue in project bazel by bazelbuild.
the class MemoizingEvaluatorTest method incrementalAddedDependency.
@Test
public void incrementalAddedDependency() throws Exception {
tester.getOrCreate("a").addDependency("b").setComputedValue(CONCATENATE);
tester.set("b", new StringValue("first"));
tester.set("c", new StringValue("second"));
tester.evalAndGet("a");
tester.getOrCreate("a").addDependency("c");
tester.set("b", new StringValue("now"));
tester.invalidate();
StringValue value = (StringValue) tester.evalAndGet("a");
assertEquals("nowsecond", value.getValue());
}
use of com.google.devtools.build.skyframe.GraphTester.StringValue in project bazel by bazelbuild.
the class MemoizingEvaluatorTest method cycleAboveIndependentCycle.
/** @see ParallelEvaluatorTest#cycleAboveIndependentCycle() */
@Test
public void cycleAboveIndependentCycle() throws Exception {
makeGraphDeterministic();
SkyKey aKey = GraphTester.toSkyKey("a");
final SkyKey bKey = GraphTester.toSkyKey("b");
SkyKey cKey = GraphTester.toSkyKey("c");
final SkyKey leafKey = GraphTester.toSkyKey("leaf");
// When aKey depends on leafKey and bKey,
tester.getOrCreate(aKey).setBuilder(new SkyFunction() {
@Nullable
@Override
public SkyValue compute(SkyKey skyKey, Environment env) throws InterruptedException {
env.getValues(ImmutableList.of(leafKey, bKey));
return null;
}
@Nullable
@Override
public String extractTag(SkyKey skyKey) {
return null;
}
});
// And bKey depends on cKey,
tester.getOrCreate(bKey).addDependency(cKey);
// And cKey depends on aKey and bKey in that order,
tester.getOrCreate(cKey).addDependency(aKey).addDependency(bKey);
// And leafKey is a leaf node,
tester.set(leafKey, new StringValue("leafy"));
// Then when we evaluate,
EvaluationResult<StringValue> result = tester.eval(/*keepGoing=*/
true, aKey);
// aKey has an error,
assertEquals(null, result.get(aKey));
if (cyclesDetected()) {
// And both cycles were found underneath aKey: the (aKey->bKey->cKey) cycle, and the
// aKey->(bKey->cKey) cycle. This is because cKey depended on aKey and then bKey, so it pushed
// them down on the stack in that order, so bKey was processed first. It found its cycle, then
// popped off the stack, and then aKey was processed and found its cycle.
assertThatEvaluationResult(result).hasErrorEntryForKeyThat(aKey).hasCycleInfoThat().containsExactly(new CycleInfo(ImmutableList.of(aKey, bKey, cKey)), new CycleInfo(ImmutableList.of(aKey), ImmutableList.of(bKey, cKey)));
} else {
assertThatEvaluationResult(result).hasErrorEntryForKeyThat(aKey).hasCycleInfoThat().hasSize(1);
}
// When leafKey is changed, so that aKey will be marked as NEEDS_REBUILDING,
tester.set(leafKey, new StringValue("crunchy"));
// And cKey is invalidated, so that cycle checking will have to explore the full graph,
tester.getOrCreate(cKey, /*markAsModified=*/
true);
tester.invalidate();
// Then when we evaluate,
EvaluationResult<StringValue> result2 = tester.eval(/*keepGoing=*/
true, aKey);
// Things are just as before.
assertEquals(null, result2.get(aKey));
if (cyclesDetected()) {
assertThatEvaluationResult(result).hasErrorEntryForKeyThat(aKey).hasCycleInfoThat().containsExactly(new CycleInfo(ImmutableList.of(aKey, bKey, cKey)), new CycleInfo(ImmutableList.of(aKey), ImmutableList.of(bKey, cKey)));
} else {
assertThatEvaluationResult(result).hasErrorEntryForKeyThat(aKey).hasCycleInfoThat().hasSize(1);
}
}
use of com.google.devtools.build.skyframe.GraphTester.StringValue in project bazel by bazelbuild.
the class MemoizingEvaluatorTest method cycleWithDirtyValue.
/** Regression test: "crash in cycle checker with dirty values". */
@Test
public void cycleWithDirtyValue() throws Exception {
initializeTester();
SkyKey cycleKey1 = GraphTester.toSkyKey("cycleKey1");
SkyKey cycleKey2 = GraphTester.toSkyKey("cycleKey2");
tester.getOrCreate(cycleKey1).addDependency(cycleKey2).setComputedValue(COPY);
tester.getOrCreate(cycleKey2).addDependency(cycleKey1).setComputedValue(COPY);
EvaluationResult<StringValue> result = tester.eval(/*keepGoing=*/
true, cycleKey1);
assertEquals(null, result.get(cycleKey1));
ErrorInfo errorInfo = result.getError(cycleKey1);
CycleInfo cycleInfo = Iterables.getOnlyElement(errorInfo.getCycleInfo());
if (cyclesDetected()) {
assertThat(cycleInfo.getCycle()).containsExactly(cycleKey1, cycleKey2).inOrder();
assertThat(cycleInfo.getPathToCycle()).isEmpty();
}
tester.getOrCreate(cycleKey1, /*markAsModified=*/
true);
tester.invalidate();
result = tester.eval(/*keepGoing=*/
true, cycleKey1);
assertEquals(null, result.get(cycleKey1));
errorInfo = result.getError(cycleKey1);
cycleInfo = Iterables.getOnlyElement(errorInfo.getCycleInfo());
if (cyclesDetected()) {
assertThat(cycleInfo.getCycle()).containsExactly(cycleKey1, cycleKey2).inOrder();
assertThat(cycleInfo.getPathToCycle()).isEmpty();
}
}
use of com.google.devtools.build.skyframe.GraphTester.StringValue in project bazel by bazelbuild.
the class MemoizingEvaluatorTest method limitEvaluatorThreads.
@Test
public void limitEvaluatorThreads() throws Exception {
initializeTester();
int numKeys = 10;
final Object lock = new Object();
final AtomicInteger inProgressCount = new AtomicInteger();
final int[] maxValue = { 0 };
SkyKey topLevel = GraphTester.toSkyKey("toplevel");
TestFunction topLevelBuilder = tester.getOrCreate(topLevel);
for (int i = 0; i < numKeys; i++) {
topLevelBuilder.addDependency("subKey" + i);
tester.getOrCreate("subKey" + i).setComputedValue(new ValueComputer() {
@Override
public SkyValue compute(Map<SkyKey, SkyValue> deps, SkyFunction.Environment env) {
int val = inProgressCount.incrementAndGet();
synchronized (lock) {
if (val > maxValue[0]) {
maxValue[0] = val;
}
}
Uninterruptibles.sleepUninterruptibly(5, TimeUnit.SECONDS);
inProgressCount.decrementAndGet();
return new StringValue("abc");
}
});
}
topLevelBuilder.setConstantValue(new StringValue("xyz"));
EvaluationResult<StringValue> result = tester.eval(/*keepGoing=*/
true, /*numThreads=*/
5, topLevel);
assertFalse(result.hasError());
assertEquals(5, maxValue[0]);
}
Aggregations