Search in sources :

Example 21 with ProcessResult

use of com.facebook.buck.testutil.integration.ProjectWorkspace.ProcessResult 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 22 with ProcessResult

use of com.facebook.buck.testutil.integration.ProjectWorkspace.ProcessResult in project buck by facebook.

the class DaemonIntegrationTest method whenAppBuckFileInvalidatedThenRebuildFails.

@Test
public void whenAppBuckFileInvalidatedThenRebuildFails() throws IOException, InterruptedException {
    final ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "file_watching", tmp);
    workspace.setUp();
    workspace.runBuckdCommand("build", "app").assertSuccess();
    String fileName = "apps/myapp/BUCK";
    Files.write(workspace.getPath(fileName), "Some Illegal Python".getBytes(Charsets.UTF_8));
    ProcessResult result = workspace.runBuckdCommand("build", "app");
    assertThat("Failure should be due to syntax error.", result.getStderr(), containsString("Syntax error"));
    result.assertFailure();
}
Also used : ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) ProcessResult(com.facebook.buck.testutil.integration.ProjectWorkspace.ProcessResult) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 23 with ProcessResult

use of com.facebook.buck.testutil.integration.ProjectWorkspace.ProcessResult in project buck by facebook.

the class DaemonIntegrationTest method whenNativeBuckTargetInvalidatedThenRebuildFails.

@Test
public void whenNativeBuckTargetInvalidatedThenRebuildFails() throws IOException, InterruptedException {
    final ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "file_watching", tmp);
    workspace.setUp();
    ProcessResult result = workspace.runBuckdCommand("run", "//native/main:main");
    result.assertSuccess();
    assertThat("Output should contain 'my_string_123_my_string'", result.getStdout(), containsString("my_string_123_my_string"));
    workspace.replaceFileContents("native/lib/BUCK", "123", "456");
    result = workspace.runBuckdCommand("run", "//native/main:main");
    result.assertSuccess();
    assertThat("Output should contain 'my_string_456_my_string'", result.getStdout(), containsString("my_string_456_my_string"));
}
Also used : ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) ProcessResult(com.facebook.buck.testutil.integration.ProjectWorkspace.ProcessResult) Test(org.junit.Test)

Example 24 with ProcessResult

use of com.facebook.buck.testutil.integration.ProjectWorkspace.ProcessResult in project buck by facebook.

the class DaemonIntegrationTest method whenBuckBuiltTwiceLogIsPresent.

@Test
public void whenBuckBuiltTwiceLogIsPresent() throws IOException, InterruptedException {
    final ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "file_watching", tmp);
    workspace.setUp();
    workspace.runBuckdCommand("build", "//java/com/example/activity:activity").assertSuccess();
    Path buildLogFile = workspace.getPath("buck-out/bin/build.log");
    assertTrue(Files.isRegularFile(buildLogFile));
    assertThat(Files.readAllLines(buildLogFile), hasItem(containsString("BUILT_LOCALLY")));
    Files.delete(buildLogFile);
    ProcessResult rebuild = workspace.runBuckdCommand("build", "//java/com/example/activity:activity");
    rebuild.assertSuccess();
    buildLogFile = workspace.getPath("buck-out/bin/build.log");
    assertTrue(Files.isRegularFile(buildLogFile));
    assertThat(Files.readAllLines(buildLogFile), not(hasItem(containsString("BUILT_LOCALLY"))));
}
Also used : Path(java.nio.file.Path) ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) ProcessResult(com.facebook.buck.testutil.integration.ProjectWorkspace.ProcessResult) Test(org.junit.Test)

Example 25 with ProcessResult

use of com.facebook.buck.testutil.integration.ProjectWorkspace.ProcessResult in project buck by facebook.

the class AuditRulesCommandIntegrationTest method testBuckAuditRules.

@Test
public void testBuckAuditRules() throws IOException {
    ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "audit_rules", tmp);
    workspace.setUp();
    // Print all of the rules in a file.
    ProcessResult result1 = workspace.runBuckCommand("audit", "rules", "example/BUCK");
    result1.assertSuccess();
    assertThat(result1.getStdout(), MoreStringsForTests.equalToIgnoringPlatformNewlines(workspace.getFileContents("stdout.all")));
    // Print all of the rules filtered by type.
    ProcessResult result2 = workspace.runBuckCommand("audit", "rules", "--type", "genrule", "example/BUCK");
    result2.assertSuccess();
    assertThat(result2.getStdout(), MoreStringsForTests.equalToIgnoringPlatformNewlines(workspace.getFileContents("stdout.genrule")));
    // Print all of the rules using multiple filters.
    ProcessResult result3 = workspace.runBuckCommand("audit", "rules", "-t", "genrule", "-t", "keystore", "example/BUCK");
    result3.assertSuccess();
    assertThat(result3.getStdout(), MoreStringsForTests.equalToIgnoringPlatformNewlines(workspace.getFileContents("stdout.all")));
}
Also used : ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) ProcessResult(com.facebook.buck.testutil.integration.ProjectWorkspace.ProcessResult) Test(org.junit.Test)

Aggregations

ProcessResult (com.facebook.buck.testutil.integration.ProjectWorkspace.ProcessResult)175 Test (org.junit.Test)174 ProjectWorkspace (com.facebook.buck.testutil.integration.ProjectWorkspace)127 Path (java.nio.file.Path)21 Matchers.containsString (org.hamcrest.Matchers.containsString)20 BuildTarget (com.facebook.buck.model.BuildTarget)17 JsonNode (com.fasterxml.jackson.databind.JsonNode)8 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)8 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)6 TestContext (com.facebook.buck.testutil.integration.TestContext)4 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)3 ZipInspector (com.facebook.buck.testutil.integration.ZipInspector)3 ZipFile (java.util.zip.ZipFile)3 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)2 DelegatingInputStream (com.facebook.buck.testutil.integration.DelegatingInputStream)2 CapturingPrintStream (com.facebook.buck.util.CapturingPrintStream)2 File (java.io.File)2 Charset (java.nio.charset.Charset)2 FileTime (java.nio.file.attribute.FileTime)2 ArtifactCache (com.facebook.buck.artifact_cache.ArtifactCache)1