use of com.google.devtools.build.lib.actions.BuildFailedException in project bazel by bazelbuild.
the class TreeArtifactBuildTest method testOneExpandedActionThrowsInActionTemplate.
@Test
public void testOneExpandedActionThrowsInActionTemplate() throws Throwable {
// expect errors
reporter.removeHandler(failFastHandler);
// artifact1 is a tree artifact generated by a TouchingTestAction.
Artifact artifact1 = createTreeArtifact("treeArtifact1");
TreeFileArtifact treeFileArtifactA = ActionInputHelper.treeFileArtifact(artifact1, new PathFragment("child1"));
TreeFileArtifact treeFileArtifactB = ActionInputHelper.treeFileArtifact(artifact1, new PathFragment("child2"));
registerAction(new TouchingTestAction(treeFileArtifactA, treeFileArtifactB));
// artifact2 is a tree artifact generated by an action template.
Artifact artifact2 = createTreeArtifact("treeArtifact2");
SpawnActionTemplate actionTemplate = ActionsTestUtil.createDummySpawnActionTemplate(artifact1, artifact2);
registerAction(actionTemplate);
// We mock out the action template function to expand into two actions:
// One Action that touches the output file.
// The other action that just throws when executed.
TreeFileArtifact expectedOutputTreeFileArtifact1 = ActionInputHelper.treeFileArtifact(artifact2, new PathFragment("child1"));
TreeFileArtifact expectedOutputTreeFileArtifact2 = ActionInputHelper.treeFileArtifact(artifact2, new PathFragment("child2"));
Action generateOutputAction = new DummyAction(ImmutableList.<Artifact>of(treeFileArtifactA), expectedOutputTreeFileArtifact1);
Action throwingAction = new ThrowingDummyAction(ImmutableList.<Artifact>of(treeFileArtifactB), ImmutableList.<Artifact>of(expectedOutputTreeFileArtifact2));
actionTemplateExpansionFunction = new DummyActionTemplateExpansionFunction(ImmutableMultimap.<ActionTemplate<?>, Action>of(actionTemplate, generateOutputAction, actionTemplate, throwingAction));
try {
buildArtifact(artifact2);
fail("Expected BuildFailedException");
} catch (BuildFailedException e) {
assertThat(e.getMessage()).contains("Throwing dummy action");
}
}
use of com.google.devtools.build.lib.actions.BuildFailedException in project bazel by bazelbuild.
the class TreeArtifactBuildTest method testRelativeSymlinkTraversingOutsideOfTreeArtifactRejected.
@Test
public void testRelativeSymlinkTraversingOutsideOfTreeArtifactRejected() throws Exception {
// Failure expected
StoredEventHandler storingEventHandler = new StoredEventHandler();
reporter.removeHandler(failFastHandler);
reporter.addHandler(storingEventHandler);
final Artifact out = createTreeArtifact("output");
TreeArtifactTestAction action = new TreeArtifactTestAction(out) {
@Override
public void execute(ActionExecutionContext actionExecutionContext) {
try {
writeFile(out.getPath().getChild("one"), "one");
writeFile(out.getPath().getChild("two"), "two");
FileSystemUtils.ensureSymbolicLink(out.getPath().getChild("links").getChild("link"), "../../output/random/pointer");
} catch (Exception e) {
throw new RuntimeException(e);
}
}
};
registerAction(action);
try {
buildArtifact(action.getSoleOutput());
// Should have thrown
fail();
} catch (BuildFailedException e) {
List<Event> errors = ImmutableList.copyOf(Iterables.filter(storingEventHandler.getEvents(), IS_ERROR_EVENT));
assertThat(errors).hasSize(2);
assertThat(errors.get(0).getMessage()).contains("A TreeArtifact may not contain relative symlinks whose target paths traverse " + "outside of the TreeArtifact");
assertThat(errors.get(1).getMessage()).contains("not all outputs were created or valid");
}
}
use of com.google.devtools.build.lib.actions.BuildFailedException in project bazel by bazelbuild.
the class TreeArtifactBuildTest method testInputTreeArtifactCreationFailedInActionTemplate.
@Test
public void testInputTreeArtifactCreationFailedInActionTemplate() throws Throwable {
// expect errors
reporter.removeHandler(failFastHandler);
// artifact1 is created by a action that throws.
Artifact artifact1 = createTreeArtifact("treeArtifact1");
registerAction(new ThrowingDummyAction(ImmutableList.<Artifact>of(), ImmutableList.of(artifact1)));
// artifact2 is a tree artifact generated by an action template.
Artifact artifact2 = createTreeArtifact("treeArtifact2");
SpawnActionTemplate actionTemplate = ActionsTestUtil.createDummySpawnActionTemplate(artifact1, artifact2);
registerAction(actionTemplate);
try {
buildArtifact(artifact2);
fail("Expected BuildFailedException");
} catch (BuildFailedException e) {
assertThat(e.getMessage()).contains("Throwing dummy action");
}
}
use of com.google.devtools.build.lib.actions.BuildFailedException in project bazel by bazelbuild.
the class ParallelBuilderTest method testWaitsForSubprocesses.
// Regression test for bug fixed in CL 3548332: builder was not waiting for
// all its subprocesses to terminate.
@Test
public void testWaitsForSubprocesses() throws Exception {
final Semaphore semaphore = new Semaphore(1);
final boolean[] finished = { false };
// t=0: semaphore acquired
semaphore.acquireUninterruptibly();
// This arrangement ensures that the "bar" action tries to run for about
// 100ms after the "foo" action has completed (failed).
// [action] -> foo
Artifact foo = createDerivedArtifact("foo");
Callable<Void> makeFoo = new Callable<Void>() {
@Override
public Void call() throws IOException {
// t=2: semaphore re-acquired
semaphore.acquireUninterruptibly();
throw new IOException("foo action failed");
}
};
registerAction(new TestAction(makeFoo, Artifact.NO_ARTIFACTS, ImmutableList.of(foo)));
// [action] -> bar
Artifact bar = createDerivedArtifact("bar");
Runnable makeBar = new Runnable() {
@Override
public void run() {
// t=1: semaphore released
semaphore.release();
try {
// 100ms
Thread.sleep(100);
} catch (InterruptedException e) {
// This might happen (though not necessarily). The
// ParallelBuilder interrupts all its workers at the first sign
// of trouble.
}
finished[0] = true;
}
};
registerAction(new TestAction(makeBar, emptySet, asSet(bar)));
// Don't fail fast when we encounter the error
reporter.removeHandler(failFastHandler);
try {
buildArtifacts(foo, bar);
fail();
} catch (BuildFailedException e) {
assertThat(e.getMessage()).contains("TestAction failed due to exception: foo action failed");
assertContainsEvent("TestAction failed due to exception: foo action failed");
}
assertTrue("bar action not finished, yet buildArtifacts has completed.", finished[0]);
}
use of com.google.devtools.build.lib.actions.BuildFailedException in project bazel by bazelbuild.
the class ParallelBuilderTest method testUpdateCacheError.
@Test
public void testUpdateCacheError() throws Exception {
FileSystem fs = new InMemoryFileSystem() {
@Override
public FileStatus stat(Path path, boolean followSymlinks) throws IOException {
final FileStatus stat = super.stat(path, followSymlinks);
if (path.toString().endsWith("/out/foo")) {
return new FileStatus() {
private final FileStatus original = stat;
@Override
public boolean isSymbolicLink() {
return original.isSymbolicLink();
}
@Override
public boolean isFile() {
return original.isFile();
}
@Override
public boolean isDirectory() {
return original.isDirectory();
}
@Override
public boolean isSpecialFile() {
return original.isSpecialFile();
}
@Override
public long getSize() throws IOException {
return original.getSize();
}
@Override
public long getNodeId() throws IOException {
return original.getNodeId();
}
@Override
public long getLastModifiedTime() throws IOException {
throw new IOException();
}
@Override
public long getLastChangeTime() throws IOException {
return original.getLastChangeTime();
}
};
}
return stat;
}
};
Artifact foo = createDerivedArtifact(fs, "foo");
registerAction(new TestAction(TestAction.NO_EFFECT, emptySet, ImmutableList.of(foo)));
reporter.removeHandler(failFastHandler);
try {
buildArtifacts(foo);
fail("Expected to fail");
} catch (BuildFailedException e) {
assertContainsEvent("not all outputs were created or valid");
}
}
Aggregations