use of com.google.devtools.build.lib.actions.ActionExecutionContext in project bazel by bazelbuild.
the class ParallelBuilderTest method assertNoNewJobsAreRunAfterFirstFailure.
// Regression test for bug #735765, "ParallelBuilder still issues new jobs
// after one has failed, without --keep-going." The incorrect behaviour is
// that, when the first job fails, while no new jobs are added to the queue
// of runnable jobs, the queue may have lots of work in it, and the
// ParallelBuilder always completes these jobs before it returns. The
// correct behaviour is to discard all the jobs in the queue after the first
// one fails.
public void assertNoNewJobsAreRunAfterFirstFailure(final boolean catastrophe, boolean keepGoing) throws Exception {
// Strategy: Limit parallelism to 3. Enqueue 10 runnable tasks that run
// for an appreciable period (say 100ms). Ensure that at most 3 of those
// tasks completed. This proves that all runnable tasks were dropped from
// the queue after the first batch (which included errors) was finished.
// It should be pretty robust even in the face of timing variations.
final AtomicInteger completedTasks = new AtomicInteger(0);
int numJobs = 50;
Artifact[] artifacts = new Artifact[numJobs];
for (int ii = 0; ii < numJobs; ++ii) {
Artifact out = createDerivedArtifact(ii + ".out");
List<Artifact> inputs = (catastrophe && ii > 10) ? ImmutableList.of(artifacts[0]) : Artifact.NO_ARTIFACTS;
final int iCopy = ii;
registerAction(new TestAction(new Callable<Void>() {
@Override
public Void call() throws Exception {
// 100ms
Thread.sleep(100);
completedTasks.getAndIncrement();
throw new IOException("task failed");
}
}, inputs, ImmutableList.of(out)) {
@Override
public void execute(ActionExecutionContext actionExecutionContext) throws ActionExecutionException {
if (catastrophe && iCopy == 0) {
try {
// 300ms
Thread.sleep(300);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
completedTasks.getAndIncrement();
throw new ActionExecutionException("This is a catastrophe", this, true);
}
super.execute(actionExecutionContext);
}
});
artifacts[ii] = out;
}
// Don't fail fast when we encounter the error
reporter.removeHandler(failFastHandler);
try {
buildArtifacts(createBuilder(3, keepGoing), artifacts);
fail();
} catch (BuildFailedException e) {
assertContainsEvent("task failed");
}
if (completedTasks.get() >= numJobs) {
fail("Expected early termination due to failed task, but all tasks ran to completion.");
}
}
use of com.google.devtools.build.lib.actions.ActionExecutionContext in project bazel by bazelbuild.
the class FileWriteActionTestCase method createExecutorAndContext.
@Before
public final void createExecutorAndContext() throws Exception {
executor = new TestExecutorBuilder(directories, binTools).build();
context = new ActionExecutionContext(executor, null, null, new FileOutErr(), ImmutableMap.<String, String>of(), null);
}
use of com.google.devtools.build.lib.actions.ActionExecutionContext in project bazel by bazelbuild.
the class PopulateTreeArtifactActionTest method testEmptyTreeArtifactInputAndOutput.
@Test
public void testEmptyTreeArtifactInputAndOutput() throws Exception {
Action action = createPopulateTreeArtifactAction();
scratch.overwriteFile("archiveManifest.txt", "");
ArrayList<Artifact> treeFileArtifacts = new ArrayList<Artifact>();
ActionExecutionContext executionContext = actionExecutionContext(treeFileArtifacts);
action.execute(executionContext);
assertThat(treeFileArtifacts).isEmpty();
}
use of com.google.devtools.build.lib.actions.ActionExecutionContext in project bazel by bazelbuild.
the class ActionDataTest method testArgumentToBuildArtifactsIsPassedDownToAction.
@Test
public void testArgumentToBuildArtifactsIsPassedDownToAction() throws Exception {
class MyAction extends AbstractAction {
Object executor = null;
public MyAction(Collection<Artifact> outputs) {
super(ActionsTestUtil.NULL_ACTION_OWNER, ImmutableList.<Artifact>of(), outputs);
}
@Override
public void execute(ActionExecutionContext actionExecutionContext) throws ActionExecutionException {
this.executor = actionExecutionContext.getExecutor();
try {
FileSystemUtils.createEmptyFile(getPrimaryOutput().getPath());
} catch (IOException e) {
throw new ActionExecutionException("failed: ", e, this, false);
}
}
@Override
protected String computeKey() {
return "MyAction";
}
@Override
public String getMnemonic() {
return "MyAction";
}
}
Artifact output = createDerivedArtifact("foo");
Set<Artifact> outputs = Sets.newHashSet(output);
MyAction action = new MyAction(outputs);
registerAction(action);
Executor executor = new DummyExecutor(scratch.dir("/"));
amnesiacBuilder().buildArtifacts(reporter, outputs, null, null, null, null, executor, null, /*explain=*/
false, null, null);
assertSame(executor, action.executor);
executor = new DummyExecutor(scratch.dir("/"));
amnesiacBuilder().buildArtifacts(reporter, outputs, null, null, null, null, executor, null, /*explain=*/
false, null, null);
assertSame(executor, action.executor);
}
Aggregations