use of com.facebook.buck.test.TestRunningOptions 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);
}
}
Aggregations