use of com.google.devtools.build.skyframe.GraphTester.StringValue in project bazel by bazelbuild.
the class ParallelEvaluatorTest method errorValueStored.
@Test
public void errorValueStored() throws Exception {
graph = new InMemoryGraphImpl();
SkyKey errorKey = GraphTester.toSkyKey("my_error_value");
tester.getOrCreate(errorKey).setHasError(true);
EvaluationResult<StringValue> result = eval(false, ImmutableList.of(errorKey));
assertThat(result.keyNames()).isEmpty();
assertThat(result.errorMap().keySet()).containsExactly(errorKey);
ErrorInfo errorInfo = result.getError();
assertThat(errorInfo.getRootCauses()).containsExactly(errorKey);
// Update value. But builder won't rebuild it.
tester.getOrCreate(errorKey).setHasError(false);
tester.set(errorKey, new StringValue("no error?"));
result = eval(false, ImmutableList.of(errorKey));
assertThat(result.keyNames()).isEmpty();
assertThat(result.errorMap().keySet()).containsExactly(errorKey);
errorInfo = result.getError();
assertThat(errorInfo.getRootCauses()).containsExactly(errorKey);
}
use of com.google.devtools.build.skyframe.GraphTester.StringValue in project bazel by bazelbuild.
the class ParallelEvaluatorTest method transformErrorDepOneLevelDownKeepGoing.
@Test
public void transformErrorDepOneLevelDownKeepGoing() throws Exception {
graph = new InMemoryGraphImpl();
SkyKey errorKey = GraphTester.toSkyKey("my_error_value");
tester.getOrCreate(errorKey).setHasError(true);
tester.set("after", new StringValue("after"));
SkyKey parentErrorKey = GraphTester.toSkyKey("parent");
tester.getOrCreate(parentErrorKey).addErrorDependency(errorKey, new StringValue("recovered"));
tester.set(parentErrorKey, new StringValue("parent value"));
SkyKey topKey = GraphTester.toSkyKey("top");
tester.getOrCreate(topKey).addDependency(parentErrorKey).addDependency("after").setComputedValue(CONCATENATE);
EvaluationResult<StringValue> result = eval(/*keepGoing=*/
true, ImmutableList.of(topKey));
assertThat(ImmutableList.<String>copyOf(result.<String>keyNames())).containsExactly("top");
assertEquals("parent valueafter", result.get(topKey).getValue());
assertThat(result.errorMap()).isEmpty();
}
use of com.google.devtools.build.skyframe.GraphTester.StringValue in project bazel by bazelbuild.
the class ParallelEvaluatorTest method storedEventFilter.
@Test
public void storedEventFilter() throws Exception {
graph = new InMemoryGraphImpl();
SkyKey a = GraphTester.toSkyKey("a");
final AtomicBoolean evaluated = new AtomicBoolean(false);
tester.getOrCreate(a).setBuilder(new SkyFunction() {
@Nullable
@Override
public SkyValue compute(SkyKey skyKey, Environment env) {
evaluated.set(true);
env.getListener().handle(Event.error(null, "boop"));
env.getListener().handle(Event.warn(null, "beep"));
return new StringValue("a");
}
@Nullable
@Override
public String extractTag(SkyKey skyKey) {
return null;
}
});
ParallelEvaluator evaluator = makeEvaluator(graph, tester.getSkyFunctionMap(), /*keepGoing=*/
false, new EventFilter() {
@Override
public boolean apply(Event event) {
return event.getKind() == EventKind.ERROR;
}
@Override
public boolean storeEvents() {
return true;
}
});
evaluator.eval(ImmutableList.of(a));
assertTrue(evaluated.get());
assertEventCount(2, eventCollector);
assertContainsEvent(eventCollector, "boop");
assertContainsEvent(eventCollector, "beep");
eventCollector.clear();
evaluator = makeEvaluator(graph, tester.getSkyFunctionMap(), /*keepGoing=*/
false);
evaluated.set(false);
evaluator.eval(ImmutableList.of(a));
assertFalse(evaluated.get());
assertEventCount(1, eventCollector);
assertContainsEvent(eventCollector, "boop");
}
use of com.google.devtools.build.skyframe.GraphTester.StringValue in project bazel by bazelbuild.
the class ParallelEvaluatorTest method runDepOnErrorHaltsNoKeepGoingBuildEagerly.
public void runDepOnErrorHaltsNoKeepGoingBuildEagerly(boolean childErrorCached, final boolean handleChildError) throws Exception {
graph = new InMemoryGraphImpl();
SkyKey parentKey = GraphTester.toSkyKey("parent");
final SkyKey childKey = GraphTester.toSkyKey("child");
tester.getOrCreate(childKey).setHasError(/*hasError=*/
true);
// The parent should be built exactly twice: once during normal evaluation and once
// during error bubbling.
final AtomicInteger numParentInvocations = new AtomicInteger(0);
tester.getOrCreate(parentKey).setBuilder(new SkyFunction() {
@Override
public SkyValue compute(SkyKey skyKey, Environment env) throws SkyFunctionException, InterruptedException {
int invocations = numParentInvocations.incrementAndGet();
if (handleChildError) {
try {
SkyValue value = env.getValueOrThrow(childKey, SomeErrorException.class);
// On the first invocation, either the child error should already be cached and
// not propagated, or it should be computed freshly and not propagated. On the
// second build (error bubbling), the child error should be propagated.
assertTrue("bogus non-null value " + value, value == null);
assertEquals("parent incorrectly re-computed during normal evaluation", 1, invocations);
assertFalse("child error not propagated during error bubbling", env.inErrorBubblingForTesting());
return value;
} catch (SomeErrorException e) {
assertTrue("child error propagated during normal evaluation", env.inErrorBubblingForTesting());
assertEquals(2, invocations);
return null;
}
} else {
if (invocations == 1) {
assertFalse("parent's first computation should be during normal evaluation", env.inErrorBubblingForTesting());
return env.getValue(childKey);
} else {
assertEquals(2, invocations);
assertTrue("parent incorrectly re-computed during normal evaluation", env.inErrorBubblingForTesting());
return env.getValue(childKey);
}
}
}
@Override
public String extractTag(SkyKey skyKey) {
return null;
}
});
if (childErrorCached) {
// Ensure that the child is already in the graph.
evalValueInError(childKey);
}
EvaluationResult<StringValue> result = eval(/*keepGoing=*/
false, ImmutableList.of(parentKey));
assertEquals(2, numParentInvocations.get());
assertTrue(result.hasError());
assertEquals(childKey, result.getError().getRootCauseOfException());
}
use of com.google.devtools.build.skyframe.GraphTester.StringValue in project bazel by bazelbuild.
the class ParallelEvaluatorTest method twoErrors.
@Test
public void twoErrors() throws Exception {
graph = new InMemoryGraphImpl();
SkyKey firstError = GraphTester.toSkyKey("error1");
SkyKey secondError = GraphTester.toSkyKey("error2");
CountDownLatch firstStart = new CountDownLatch(1);
CountDownLatch secondStart = new CountDownLatch(1);
tester.getOrCreate(firstError).setBuilder(new ChainedFunction(firstStart, secondStart, /*notifyFinish=*/
null, /*waitForException=*/
false, /*value=*/
null, ImmutableList.<SkyKey>of()));
tester.getOrCreate(secondError).setBuilder(new ChainedFunction(secondStart, firstStart, /*notifyFinish=*/
null, /*waitForException=*/
false, /*value=*/
null, ImmutableList.<SkyKey>of()));
EvaluationResult<StringValue> result = eval(/*keepGoing=*/
false, firstError, secondError);
assertTrue(result.toString(), result.hasError());
// With keepGoing=false, the eval call will terminate with exactly one error (the first one
// thrown). But the first one thrown here is non-deterministic since we synchronize the
// builders so that they run at roughly the same time.
assertThat(ImmutableSet.of(firstError, secondError)).contains(Iterables.getOnlyElement(result.errorMap().keySet()));
}
Aggregations