Search in sources :

Example 1 with TestContext

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

the class DaemonIntegrationTest method whenClientDisconnectionDetectedThenBuildIsInterrupted.

/**
   * 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 whenClientDisconnectionDetectedThenBuildIsInterrupted() throws InterruptedException, IOException {
    // Sub process interruption not supported on Windows.
    assumeTrue(Platform.detect() != Platform.WINDOWS);
    // Stream timeout > test timeout.
    final long timeoutMillis = 2000;
    // Disconnect before test timeout.
    final long disconnectMillis = 100;
    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.createDisconnectionStream(disconnectMillis), 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 2 with TestContext

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

the class DaemonIntegrationTest method whenClientDisconnectionDetectedThenTestIsInterrupted.

/**
   * This verifies that a client disconnection will be detected by a Nailgun
   * NGInputStream reading from an empty heartbeat stream and that the generated
   * InterruptedException will interrupt command execution causing it to fail.
   */
@Test
public void whenClientDisconnectionDetectedThenTestIsInterrupted() throws InterruptedException, IOException {
    // Sub process interruption not supported on Windows.
    assumeTrue(Platform.detect() != Platform.WINDOWS);
    // Stream timeout > test timeout.
    final long timeoutMillis = 2000;
    // Disconnect before test timeout.
    final long disconnectMillis = 100;
    final ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "exclusive_execution", tmp);
    workspace.setUp();
    // Start with an input stream that sends heartbeats at a regular rate.
    final DelegatingInputStream inputStream = new DelegatingInputStream(TestContext.createHeartBeatStream(timeoutMillis / 10));
    // Build an NGContext connected to an NGInputStream reading from stream that will timeout.
    try (TestContext context = new TestContext(ImmutableMap.copyOf(System.getenv()), inputStream, timeoutMillis)) {
        ProcessResult result = workspace.runBuckdCommand(context, new CapturingPrintStream() {

            @Override
            public void println(String x) {
                if (x.contains("TESTING //:test")) {
                    // When tests start running, make the heartbeat stream simulate a disconnection.
                    inputStream.setDelegate(TestContext.createDisconnectionStream(disconnectMillis));
                }
                super.println(x);
            }
        }, "test", "//:test");
        result.assertFailure();
        assertThat(result.getStderr(), containsString("InterruptedException"));
    }
}
Also used : ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) CapturingPrintStream(com.facebook.buck.util.CapturingPrintStream) DelegatingInputStream(com.facebook.buck.testutil.integration.DelegatingInputStream) TestContext(com.facebook.buck.testutil.integration.TestContext) ProcessResult(com.facebook.buck.testutil.integration.ProjectWorkspace.ProcessResult) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 3 with TestContext

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

the class WebServerBuckEventListenerTest method hasBuckTestStartedThenEventsCalled.

@Test
@Ignore
public void hasBuckTestStartedThenEventsCalled() throws IOException, InterruptedException {
    final ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "buck_events/test", 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);
    //Individual test started
    //This target has only 1 test
    webServerBuckEventListener.testAwaitingResults(anyObject(IndividualTestEvent.Started.class));
    EasyMock.expectLastCall().times(1);
    //Individual test finished
    webServerBuckEventListener.testResultsAvailable(anyObject(IndividualTestEvent.Finished.class));
    EasyMock.expectLastCall().times(1);
    //Test started
    webServerBuckEventListener.testRunStarted(anyObject(TestRunEvent.Started.class));
    EasyMock.expectLastCall().times(1);
    //Test finished
    webServerBuckEventListener.testRunCompleted(anyObject(TestRunEvent.Finished.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(), "test", "//:simple_test");
    build.assertSuccess();
    verify(webServerBuckEventListener);
}
Also used : ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) BuildId(com.facebook.buck.model.BuildId) TestContext(com.facebook.buck.testutil.integration.TestContext) WebServerBuckEventListener(com.facebook.buck.httpserver.WebServerBuckEventListener) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 4 with TestContext

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

the class DaemonIntegrationTest method whenClientTimeoutDetectedThenMainThreadIsInterrupted.

/**
   * Verifies that a client timeout will be detected by a Nailgun
   * NGInputStream reading from a blocking heartbeat stream.
   */
@Test(expected = InterruptedException.class)
public void whenClientTimeoutDetectedThenMainThreadIsInterrupted() throws InterruptedException, IOException {
    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 a stream that will timeout.
    Thread.currentThread().setName("Test");
    try (TestContext context = new TestContext(ImmutableMap.copyOf(System.getenv()), TestContext.createHeartBeatStream(intervalMillis), timeoutMillis)) {
        context.addClientListener(Thread.currentThread()::interrupt);
        Thread.sleep(1000);
        fail("Should have been interrupted.");
    }
}
Also used : ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) TestContext(com.facebook.buck.testutil.integration.TestContext) Test(org.junit.Test)

Example 5 with TestContext

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

the class DaemonIntegrationTest method whenClientTimeoutDetectedThenTestIsInterrupted.

/**
   * This verifies that a client disconnection will be detected by a Nailgun
   * NGInputStream reading from an empty heartbeat stream and that the generated
   * InterruptedException will interrupt command execution causing it to fail.
   */
@Test
public void whenClientTimeoutDetectedThenTestIsInterrupted() throws InterruptedException, IOException {
    // Sub process interruption not supported on Windows.
    assumeTrue(Platform.detect() != Platform.WINDOWS);
    final long timeoutMillis = 100;
    final ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "exclusive_execution", tmp);
    workspace.setUp();
    // Start with an input stream that sends heartbeats at a regular rate.
    final DelegatingInputStream inputStream = new DelegatingInputStream(TestContext.createHeartBeatStream(timeoutMillis / 10));
    // Build an NGContext connected to an NGInputStream reading from stream that will timeout.
    try (TestContext context = new TestContext(ImmutableMap.copyOf(System.getenv()), inputStream, timeoutMillis)) {
        ProcessResult result = workspace.runBuckdCommand(context, new CapturingPrintStream() {

            @Override
            public void println(String x) {
                if (x.contains("TESTING //:test")) {
                    // When tests start running, make the heartbeat stream simulate a disconnection.
                    inputStream.setDelegate(TestContext.createDisconnectionStream(2 * timeoutMillis));
                }
                super.println(x);
            }
        }, "test", "//:test");
        result.assertFailure();
        assertThat(result.getStderr(), containsString("InterruptedException"));
    }
}
Also used : ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) CapturingPrintStream(com.facebook.buck.util.CapturingPrintStream) DelegatingInputStream(com.facebook.buck.testutil.integration.DelegatingInputStream) TestContext(com.facebook.buck.testutil.integration.TestContext) ProcessResult(com.facebook.buck.testutil.integration.ProjectWorkspace.ProcessResult) Matchers.containsString(org.hamcrest.Matchers.containsString) 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