Search in sources :

Example 6 with TestContext

use of com.facebook.buck.testutil.integration.TestContext in project buck by facebook.

the class DaemonIntegrationTest method createRunnableCommand.

private Runnable createRunnableCommand(final int expectedExitCode, final String... args) {
    return () -> {
        try {
            Main main = new Main(new CapturingPrintStream(), new CapturingPrintStream(), new ByteArrayInputStream("".getBytes("UTF-8")));
            int exitCode = main.runMainWithExitCode(new BuildId(), tmp.getRoot(), Optional.of(new TestContext()), ImmutableMap.copyOf(System.getenv()), CommandMode.TEST, WatchmanWatcher.FreshInstanceAction.NONE, System.nanoTime(), args);
            assertEquals("Unexpected exit code.", expectedExitCode, exitCode);
        } catch (IOException e) {
            fail("Should not throw exception.");
            Throwables.throwIfUnchecked(e);
        } catch (InterruptedException e) {
            fail("Should not throw exception.");
            Thread.currentThread().interrupt();
        }
    };
}
Also used : CapturingPrintStream(com.facebook.buck.util.CapturingPrintStream) ByteArrayInputStream(java.io.ByteArrayInputStream) BuildId(com.facebook.buck.model.BuildId) TestContext(com.facebook.buck.testutil.integration.TestContext) IOException(java.io.IOException)

Example 7 with TestContext

use of com.facebook.buck.testutil.integration.TestContext in project buck by facebook.

the class DaemonIntegrationTest method whenClientTimeoutDetectedThenBuildIsInterrupted.

/**
   * This verifies that a client timeout will be detected by a Nailgun
   * NGInputStream reading from an empty heartbeat stream and that the generated
   * InterruptedException will cause command execution to fail after timeout.
   */
@Test
public void whenClientTimeoutDetectedThenBuildIsInterrupted() throws InterruptedException, IOException {
    // Sub process interruption not supported on Windows.
    assumeTrue(Platform.detect() != Platform.WINDOWS);
    final long timeoutMillis = 100;
    // Interval > timeout to trigger disconnection.
    final long intervalMillis = timeoutMillis * 2;
    final ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "exclusive_execution", tmp);
    workspace.setUp();
    // Build an NGContext connected to an NGInputStream reading from stream that will timeout.
    try (TestContext context = new TestContext(ImmutableMap.copyOf(System.getenv()), TestContext.createHeartBeatStream(intervalMillis), timeoutMillis)) {
        ProcessResult result = workspace.runBuckdCommand(context, "build", "//:sleep");
        result.assertFailure();
        assertThat(result.getStderr(), containsString("InterruptedException"));
    }
}
Also used : ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) TestContext(com.facebook.buck.testutil.integration.TestContext) ProcessResult(com.facebook.buck.testutil.integration.ProjectWorkspace.ProcessResult) Test(org.junit.Test)

Example 8 with TestContext

use of com.facebook.buck.testutil.integration.TestContext in project buck by facebook.

the class ActionGraphCacheIntegrationTest method specifyingSkipActionGraphCacheDoesNotInvalidateTheActionGraphCache.

@Test
public void specifyingSkipActionGraphCacheDoesNotInvalidateTheActionGraphCache() throws IOException {
    try (TestContext context = new TestContext()) {
        workspace.runBuckdCommand(context, "build", "//:pretend_this_is_an_expensive_rule").assertSuccess();
        assertEquals("Should be a fresh daemon, so the ActionGraph cache should be empty.", ActionGraphCacheStatus.MISS_CACHE_EMPTY, getActionGraphCacheStatus());
        workspace.runBuckdCommand(context, "build", "//:pretend_this_is_an_expensive_rule").assertSuccess();
        assertEquals("Rebuilding the rule should hit the cache.", ActionGraphCacheStatus.HIT, getActionGraphCacheStatus());
        workspace.runBuckdCommand(context, "build", "//:pretend_this_is_a_cheap_rule").assertSuccess();
        assertEquals("Building a different rule as a non-oneoff should invalidate the cache.", ActionGraphCacheStatus.MISS_TARGET_GRAPH_MISMATCH, getActionGraphCacheStatus());
        workspace.runBuckdCommand(context, "build", "//:pretend_this_is_an_expensive_rule").assertSuccess();
        assertEquals("Building a different rule as a non-oneoff should invalidate the cache again.", ActionGraphCacheStatus.MISS_TARGET_GRAPH_MISMATCH, getActionGraphCacheStatus());
        workspace.runBuckdCommand(context, "build", "--config", "client.skip-action-graph-cache=true", "//:pretend_this_is_a_cheap_rule").assertSuccess();
        assertEquals("Building a different rule as a oneoff will still be a mismatch.", ActionGraphCacheStatus.MISS_TARGET_GRAPH_MISMATCH, getActionGraphCacheStatus());
        workspace.runBuckdCommand(context, "build", "//:pretend_this_is_an_expensive_rule").assertSuccess();
        assertEquals("The ActionGraph for the expensive rule should still be in cache.", ActionGraphCacheStatus.HIT, getActionGraphCacheStatus());
    }
}
Also used : TestContext(com.facebook.buck.testutil.integration.TestContext) Test(org.junit.Test)

Example 9 with TestContext

use of com.facebook.buck.testutil.integration.TestContext in project buck by facebook.

the class WebServerBuckEventListenerTest method hasBuckCompilerErrorOccurredThenEventsCalled.

@Test
@Ignore
public void hasBuckCompilerErrorOccurredThenEventsCalled() throws IOException, InterruptedException {
    final ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "buck_events/compiler_error", tmp);
    workspace.setUp();
    WebServerBuckEventListener webServerBuckEventListener = createMock(WebServerBuckEventListener.class);
    //Build started
    webServerBuckEventListener.buildStarted(anyObject(BuildEvent.Started.class));
    EasyMock.expectLastCall().times(1);
    //Build progress Event
    webServerBuckEventListener.buildProgressUpdated(anyObject(ProgressEvent.BuildProgressUpdated.class));
    EasyMock.expectLastCall().atLeastOnce();
    //Build finished
    webServerBuckEventListener.buildFinished(anyObject(BuildEvent.Finished.class));
    EasyMock.expectLastCall().times(1);
    //Parse started
    webServerBuckEventListener.parseStarted(anyObject(ParseEvent.Started.class));
    EasyMock.expectLastCall().times(1);
    //Parse progress Event
    webServerBuckEventListener.parsingProgressUpdated(anyObject(ProgressEvent.ParsingProgressUpdated.class));
    EasyMock.expectLastCall().atLeastOnce();
    //Parse finished
    webServerBuckEventListener.parseFinished(anyObject(ParseEvent.Finished.class));
    EasyMock.expectLastCall().times(1);
    //Compiler error
    webServerBuckEventListener.compilerErrorEvent(anyObject(CompilerErrorEvent.class));
    EasyMock.expectLastCall().times(1);
    //Console event
    webServerBuckEventListener.consoleEvent(anyObject(ConsoleEvent.class));
    EasyMock.expectLastCall().times(1);
    //Output trace
    webServerBuckEventListener.outputTrace(anyObject(BuildId.class));
    EasyMock.expectLastCall().times(1);
    EasyMock.replay(webServerBuckEventListener);
    ProjectWorkspace.ProcessResult build = workspace.runBuckdCommand(new TestContext(), "build", "//:broken");
    build.assertFailure();
    verify(webServerBuckEventListener);
}
Also used : ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) BuildId(com.facebook.buck.model.BuildId) CompilerErrorEvent(com.facebook.buck.event.CompilerErrorEvent) ConsoleEvent(com.facebook.buck.event.ConsoleEvent) TestContext(com.facebook.buck.testutil.integration.TestContext) WebServerBuckEventListener(com.facebook.buck.httpserver.WebServerBuckEventListener) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 10 with TestContext

use of com.facebook.buck.testutil.integration.TestContext in project buck by facebook.

the class WebServerBuckEventListenerTest method hasBuckBuildStartedThenEventsCalled.

@Test
@Ignore
public void hasBuckBuildStartedThenEventsCalled() throws IOException, InterruptedException {
    final ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "buck_events", tmp);
    workspace.setUp();
    WebServerBuckEventListener webServerBuckEventListener = createMock(WebServerBuckEventListener.class);
    //Build started
    webServerBuckEventListener.buildStarted(anyObject(BuildEvent.Started.class));
    EasyMock.expectLastCall().times(1);
    //Build progress Event
    webServerBuckEventListener.buildProgressUpdated(anyObject(ProgressEvent.BuildProgressUpdated.class));
    EasyMock.expectLastCall().atLeastOnce();
    //Build finished
    webServerBuckEventListener.buildFinished((BuildEvent.Finished) anyObject());
    EasyMock.expectLastCall().times(1);
    //Parse started
    webServerBuckEventListener.parseStarted(anyObject(ParseEvent.Started.class));
    EasyMock.expectLastCall().times(1);
    //Parse progress Event
    webServerBuckEventListener.parsingProgressUpdated((ProgressEvent.ParsingProgressUpdated) anyObject());
    EasyMock.expectLastCall().atLeastOnce();
    //Parse finished
    webServerBuckEventListener.parseFinished((ParseEvent.Finished) anyObject());
    EasyMock.expectLastCall().times(1);
    //Output trace
    webServerBuckEventListener.outputTrace(anyObject(BuildId.class));
    EasyMock.expectLastCall().times(1);
    EasyMock.replay(webServerBuckEventListener);
    ProjectWorkspace.ProcessResult build = workspace.runBuckdCommand(new TestContext(), "build", "//:foo");
    build.assertSuccess();
    verify(webServerBuckEventListener);
}
Also used : ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) BuildId(com.facebook.buck.model.BuildId) BuildEvent(com.facebook.buck.rules.BuildEvent) ParseEvent(com.facebook.buck.parser.ParseEvent) TestContext(com.facebook.buck.testutil.integration.TestContext) WebServerBuckEventListener(com.facebook.buck.httpserver.WebServerBuckEventListener) ProgressEvent(com.facebook.buck.event.ProgressEvent) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

TestContext (com.facebook.buck.testutil.integration.TestContext)11 Test (org.junit.Test)10 ProjectWorkspace (com.facebook.buck.testutil.integration.ProjectWorkspace)9 BuildId (com.facebook.buck.model.BuildId)5 WebServerBuckEventListener (com.facebook.buck.httpserver.WebServerBuckEventListener)4 ProcessResult (com.facebook.buck.testutil.integration.ProjectWorkspace.ProcessResult)4 Ignore (org.junit.Ignore)4 CapturingPrintStream (com.facebook.buck.util.CapturingPrintStream)3 DelegatingInputStream (com.facebook.buck.testutil.integration.DelegatingInputStream)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 CompilerErrorEvent (com.facebook.buck.event.CompilerErrorEvent)1 ConsoleEvent (com.facebook.buck.event.ConsoleEvent)1 ProgressEvent (com.facebook.buck.event.ProgressEvent)1 ParseEvent (com.facebook.buck.parser.ParseEvent)1 BuildEvent (com.facebook.buck.rules.BuildEvent)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1