Search in sources :

Example 21 with ActionExecutionContext

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.");
    }
}
Also used : IOException(java.io.IOException) Artifact(com.google.devtools.build.lib.actions.Artifact) Callable(java.util.concurrent.Callable) TestAction(com.google.devtools.build.lib.actions.util.TestAction) BuildFailedException(com.google.devtools.build.lib.actions.BuildFailedException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ActionExecutionContext(com.google.devtools.build.lib.actions.ActionExecutionContext) ActionExecutionException(com.google.devtools.build.lib.actions.ActionExecutionException)

Example 22 with ActionExecutionContext

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);
}
Also used : TestExecutorBuilder(com.google.devtools.build.lib.exec.util.TestExecutorBuilder) FileOutErr(com.google.devtools.build.lib.util.io.FileOutErr) ActionExecutionContext(com.google.devtools.build.lib.actions.ActionExecutionContext) Before(org.junit.Before)

Example 23 with ActionExecutionContext

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();
}
Also used : Action(com.google.devtools.build.lib.actions.Action) ArrayList(java.util.ArrayList) ActionExecutionContext(com.google.devtools.build.lib.actions.ActionExecutionContext) SpecialArtifact(com.google.devtools.build.lib.actions.Artifact.SpecialArtifact) Artifact(com.google.devtools.build.lib.actions.Artifact) TreeFileArtifact(com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact) Test(org.junit.Test)

Example 24 with ActionExecutionContext

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);
}
Also used : DummyExecutor(com.google.devtools.build.lib.actions.util.DummyExecutor) Executor(com.google.devtools.build.lib.actions.Executor) DummyExecutor(com.google.devtools.build.lib.actions.util.DummyExecutor) ActionExecutionContext(com.google.devtools.build.lib.actions.ActionExecutionContext) Collection(java.util.Collection) IOException(java.io.IOException) ActionExecutionException(com.google.devtools.build.lib.actions.ActionExecutionException) AbstractAction(com.google.devtools.build.lib.actions.AbstractAction) Artifact(com.google.devtools.build.lib.actions.Artifact) Test(org.junit.Test)

Aggregations

ActionExecutionContext (com.google.devtools.build.lib.actions.ActionExecutionContext)24 Test (org.junit.Test)19 Artifact (com.google.devtools.build.lib.actions.Artifact)17 ActionExecutionException (com.google.devtools.build.lib.actions.ActionExecutionException)13 SpecialArtifact (com.google.devtools.build.lib.actions.Artifact.SpecialArtifact)13 TreeFileArtifact (com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact)13 IOException (java.io.IOException)12 BuildFailedException (com.google.devtools.build.lib.actions.BuildFailedException)10 Action (com.google.devtools.build.lib.actions.Action)7 ActionInputHelper.treeFileArtifact (com.google.devtools.build.lib.actions.ActionInputHelper.treeFileArtifact)7 ImmutableList (com.google.common.collect.ImmutableList)4 StoredEventHandler (com.google.devtools.build.lib.events.StoredEventHandler)4 TestExecutorBuilder (com.google.devtools.build.lib.exec.util.TestExecutorBuilder)4 List (java.util.List)4 Executor (com.google.devtools.build.lib.actions.Executor)3 FileOutErr (com.google.devtools.build.lib.util.io.FileOutErr)3 ArrayList (java.util.ArrayList)3 TestAction (com.google.devtools.build.lib.actions.util.TestAction)2 Collection (java.util.Collection)2 Before (org.junit.Before)2