use of com.google.devtools.build.skyframe.GraphTester.StringValue in project bazel by bazelbuild.
the class MemoizingEvaluatorTest method smoke.
@Test
public void smoke() throws Exception {
tester.set("x", new StringValue("y"));
StringValue value = (StringValue) tester.evalAndGet("x");
assertEquals("y", value.getValue());
}
use of com.google.devtools.build.skyframe.GraphTester.StringValue in project bazel by bazelbuild.
the class MemoizingEvaluatorTest method dirtyWithOwnErrorDependsOnTransientErrorTurningGood.
/** Regression test for crash bug. */
@Test
public void dirtyWithOwnErrorDependsOnTransientErrorTurningGood() throws Exception {
initializeTester();
final SkyKey error = GraphTester.toSkyKey("error");
tester.getOrCreate(error).setHasTransientError(true);
SkyKey topKey = GraphTester.toSkyKey("top");
SkyFunction errorFunction = new SkyFunction() {
@Override
public SkyValue compute(SkyKey skyKey, Environment env) throws GenericFunctionException, InterruptedException {
try {
return env.getValueOrThrow(error, SomeErrorException.class);
} catch (SomeErrorException e) {
throw new GenericFunctionException(e, Transience.PERSISTENT);
}
}
@Override
public String extractTag(SkyKey skyKey) {
throw new UnsupportedOperationException();
}
};
tester.getOrCreate(topKey).setBuilder(errorFunction);
EvaluationResult<StringValue> result = tester.eval(/*keepGoing=*/
false, topKey);
tester.invalidateTransientErrors();
assertThat(result.getError(topKey).getRootCauses()).containsExactly(topKey);
tester.getOrCreate(error).setHasTransientError(false);
StringValue reformed = new StringValue("reformed");
tester.set(error, reformed);
tester.getOrCreate(topKey).setBuilder(null).addDependency(error).setComputedValue(COPY);
tester.invalidate();
tester.invalidateTransientErrors();
result = tester.eval(/*keepGoing=*/
false, topKey);
assertEquals(reformed, result.get(topKey));
assertFalse(result.hasError());
}
use of com.google.devtools.build.skyframe.GraphTester.StringValue in project bazel by bazelbuild.
the class MemoizingEvaluatorTest method failedDirtyBuild.
@Test
public void failedDirtyBuild() throws Exception {
initializeTester();
SkyKey leaf = GraphTester.toSkyKey("leaf");
SkyKey top = GraphTester.toSkyKey("top");
tester.getOrCreate(top).addErrorDependency(leaf, new StringValue("recover")).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();
// Change leaf.
tester.getOrCreate(leaf, /*markAsModified=*/
true).setHasError(true);
tester.getOrCreate(top, /*markAsModified=*/
false).setHasError(true);
tester.invalidate();
EvaluationResult<StringValue> result = tester.eval(/*keepGoing=*/
false, top);
assertNull("value should not have completed evaluation", result.get(top));
assertWithMessage("The error thrown by leaf should have been swallowed by the error thrown by top").that(result.getError().getRootCauses()).containsExactly(top);
}
use of com.google.devtools.build.skyframe.GraphTester.StringValue in project bazel by bazelbuild.
the class MemoizingEvaluatorTest method warningAndErrorOnFailFastBuildAfterKeepGoingBuild.
@Test
public void warningAndErrorOnFailFastBuildAfterKeepGoingBuild() throws Exception {
SkyKey topKey = GraphTester.toSkyKey("top");
tester.set(topKey, new StringValue("top")).setWarning("warning msg").setHasError(true);
for (int i = 0; i < 2; i++) {
initializeReporter();
EvaluationResult<StringValue> result = tester.eval(i == 0, "top");
assertTrue(result.hasError());
if (rootCausesStored()) {
assertThat(result.getError(topKey).getRootCauses()).containsExactly(topKey);
}
assertEquals(topKey.toString(), result.getError(topKey).getException().getMessage());
assertTrue(result.getError(topKey).getException() instanceof SomeErrorException);
if (i == 0 || eventsStored()) {
assertContainsEvent(eventCollector, "warning msg");
assertEventCount(1, eventCollector);
}
}
}
use of com.google.devtools.build.skyframe.GraphTester.StringValue in project bazel by bazelbuild.
the class MemoizingEvaluatorTest method breakCycle.
@Test
public void breakCycle() throws Exception {
initializeTester();
SkyKey aKey = GraphTester.toSkyKey("a");
SkyKey bKey = GraphTester.toSkyKey("b");
// When aKey and bKey depend on each other,
tester.getOrCreate(aKey).addDependency(bKey);
tester.getOrCreate(bKey).addDependency(aKey);
// And they are evaluated,
EvaluationResult<StringValue> result = tester.eval(/*keepGoing=*/
true, aKey, bKey);
// Then the evaluation is in error,
assertThatEvaluationResult(result).hasError();
// And each node has the expected cycle.
assertThatEvaluationResult(result).hasErrorEntryForKeyThat(aKey).hasCycleInfoThat().isNotEmpty();
CycleInfo aCycleInfo = Iterables.getOnlyElement(result.getError(aKey).getCycleInfo());
if (cyclesDetected()) {
assertThat(aCycleInfo.getCycle()).containsExactly(aKey, bKey).inOrder();
assertThat(aCycleInfo.getPathToCycle()).isEmpty();
}
assertThatEvaluationResult(result).hasErrorEntryForKeyThat(bKey).hasCycleInfoThat().isNotEmpty();
CycleInfo bCycleInfo = Iterables.getOnlyElement(result.getError(bKey).getCycleInfo());
if (cyclesDetected()) {
assertThat(bCycleInfo.getCycle()).containsExactly(bKey, aKey).inOrder();
assertThat(bCycleInfo.getPathToCycle()).isEmpty();
}
// When both dependencies are broken,
tester.getOrCreate(bKey).removeDependency(aKey);
tester.set(bKey, new StringValue("bValue"));
tester.getOrCreate(aKey).removeDependency(bKey);
tester.set(aKey, new StringValue("aValue"));
tester.invalidate();
// And the nodes are re-evaluated,
result = tester.eval(/*keepGoing=*/
true, aKey, bKey);
// Then evaluation is successful and the nodes have the expected values.
assertThatEvaluationResult(result).hasEntryThat(aKey).isEqualTo(new StringValue("aValue"));
assertThatEvaluationResult(result).hasEntryThat(bKey).isEqualTo(new StringValue("bValue"));
}
Aggregations