Search in sources :

Example 1 with ExternalTestRunnerRule

use of com.facebook.buck.rules.ExternalTestRunnerRule in project buck by facebook.

the class TestCommand method runTestsExternal.

private int runTestsExternal(final CommandRunnerParams params, Build build, Iterable<String> command, Iterable<TestRule> testRules, SourcePathResolver pathResolver) throws InterruptedException, IOException {
    TestRunningOptions options = getTestRunningOptions(params);
    // Walk the test rules, collecting all the specs.
    List<ExternalTestRunnerTestSpec> specs = Lists.newArrayList();
    for (TestRule testRule : testRules) {
        if (!(testRule instanceof ExternalTestRunnerRule)) {
            params.getBuckEventBus().post(ConsoleEvent.severe(String.format("Test %s does not support external test running", testRule.getBuildTarget())));
            return 1;
        }
        ExternalTestRunnerRule rule = (ExternalTestRunnerRule) testRule;
        specs.add(rule.getExternalTestRunnerSpec(build.getExecutionContext(), options, pathResolver));
    }
    // Serialize the specs to a file to pass into the test runner.
    Path infoFile = params.getCell().getFilesystem().resolve(params.getCell().getFilesystem().getBuckPaths().getScratchDir()).resolve("external_runner_specs.json");
    Files.createDirectories(infoFile.getParent());
    Files.deleteIfExists(infoFile);
    params.getObjectMapper().writerWithDefaultPrettyPrinter().writeValue(infoFile.toFile(), specs);
    // Launch and run the external test runner, forwarding it's stdout/stderr to the console.
    // We wait for it to complete then returns its error code.
    ListeningProcessExecutor processExecutor = new ListeningProcessExecutor();
    ProcessExecutorParams processExecutorParams = ProcessExecutorParams.builder().addAllCommand(command).addAllCommand(withDashArguments).setEnvironment(params.getEnvironment()).addCommand("--buck-test-info", infoFile.toString()).addCommand("--jobs", String.valueOf(getConcurrencyLimit(params.getBuckConfig()).threadLimit)).setDirectory(params.getCell().getFilesystem().getRootPath()).build();
    ForwardingProcessListener processListener = new ForwardingProcessListener(Channels.newChannel(params.getConsole().getStdOut()), Channels.newChannel(params.getConsole().getStdErr()));
    ListeningProcessExecutor.LaunchedProcess process = processExecutor.launchProcess(processExecutorParams, processListener);
    try {
        return processExecutor.waitForProcess(process);
    } finally {
        processExecutor.destroyProcess(process, /* force */
        false);
        processExecutor.waitForProcess(process);
    }
}
Also used : Path(java.nio.file.Path) TestRule(com.facebook.buck.rules.TestRule) ProcessExecutorParams(com.facebook.buck.util.ProcessExecutorParams) ListeningProcessExecutor(com.facebook.buck.util.ListeningProcessExecutor) ExternalTestRunnerRule(com.facebook.buck.rules.ExternalTestRunnerRule) ForwardingProcessListener(com.facebook.buck.util.ForwardingProcessListener) TestRunningOptions(com.facebook.buck.test.TestRunningOptions) ExternalTestRunnerTestSpec(com.facebook.buck.rules.ExternalTestRunnerTestSpec)

Aggregations

ExternalTestRunnerRule (com.facebook.buck.rules.ExternalTestRunnerRule)1 ExternalTestRunnerTestSpec (com.facebook.buck.rules.ExternalTestRunnerTestSpec)1 TestRule (com.facebook.buck.rules.TestRule)1 TestRunningOptions (com.facebook.buck.test.TestRunningOptions)1 ForwardingProcessListener (com.facebook.buck.util.ForwardingProcessListener)1 ListeningProcessExecutor (com.facebook.buck.util.ListeningProcessExecutor)1 ProcessExecutorParams (com.facebook.buck.util.ProcessExecutorParams)1 Path (java.nio.file.Path)1