use of com.google.devtools.build.lib.view.test.TestStatus.TestCase in project bazel by bazelbuild.
the class WorkerTestStrategy method execInWorker.
private TestResultData execInWorker(TestRunnerAction action, ActionExecutionContext actionExecutionContext, Map<String, String> environment, List<String> startupArgs, Path execRoot, int retriesLeft) throws ExecException, InterruptedException, IOException {
Executor executor = actionExecutionContext.getExecutor();
// TODO(kush): Remove once we're out of the experimental phase.
executor.getEventHandler().handle(Event.warn("RUNNING TEST IN AN EXPERIMENTAL PERSISTENT WORKER. RESULTS MAY BE INACCURATE"));
TestResultData.Builder builder = TestResultData.newBuilder();
Path testLogPath = action.getTestLog().getPath();
Worker worker = null;
WorkerKey key = null;
long startTime = executor.getClock().currentTimeMillis();
try {
HashCode workerFilesHash = WorkerFilesHash.getWorkerFilesHash(action.getTools(), actionExecutionContext);
key = new WorkerKey(startupArgs, environment, execRoot, action.getMnemonic(), workerFilesHash, ImmutableMap.<PathFragment, Path>of(), ImmutableSet.<PathFragment>of(), /*mustBeSandboxed=*/
false);
worker = workerPool.borrowObject(key);
WorkRequest request = WorkRequest.getDefaultInstance();
request.writeDelimitedTo(worker.getOutputStream());
worker.getOutputStream().flush();
WorkResponse response = WorkResponse.parseDelimitedFrom(worker.getInputStream());
actionExecutionContext.getFileOutErr().getErrorStream().write(response.getOutputBytes().toByteArray());
long duration = executor.getClock().currentTimeMillis() - startTime;
builder.addTestTimes(duration);
builder.setRunDurationMillis(duration);
if (response.getExitCode() == 0) {
builder.setTestPassed(true).setStatus(BlazeTestStatus.PASSED).setCachable(true).setPassedLog(testLogPath.getPathString());
} else {
builder.setTestPassed(false).setStatus(BlazeTestStatus.FAILED).addFailedLogs(testLogPath.getPathString());
}
TestCase details = parseTestResult(action.resolve(actionExecutionContext.getExecutor().getExecRoot()).getXmlOutputPath());
if (details != null) {
builder.setTestCase(details);
}
return builder.build();
} catch (IOException | InterruptedException e) {
if (e instanceof InterruptedException) {
// The user pressed Ctrl-C. Get out here quick.
retriesLeft = 0;
}
if (worker != null) {
workerPool.invalidateObject(key, worker);
worker = null;
}
if (retriesLeft > 0) {
// The worker process failed, but we still have some retries left. Let's retry with a fresh
// worker.
executor.getEventHandler().handle(Event.warn(key.getMnemonic() + " worker failed (" + e + "), invalidating and retrying with new worker..."));
return execInWorker(action, actionExecutionContext, environment, startupArgs, execRoot, retriesLeft - 1);
} else {
throw new TestExecException(e.getMessage());
}
} finally {
if (worker != null) {
workerPool.returnObject(key, worker);
}
}
}
use of com.google.devtools.build.lib.view.test.TestStatus.TestCase in project bazel by bazelbuild.
the class TestSummaryTest method testFileNamesNotShown.
@Test
public void testFileNamesNotShown() throws Exception {
List<TestCase> emptyDetails = ImmutableList.of();
TestSummary summary = basicBuilder.setStatus(BlazeTestStatus.FAILED).addPassedLogs(getPathList("/apple")).addFailedLogs(getPathList("/pear")).addCoverageFiles(getPathList("/maracuja")).addFailedTestCases(emptyDetails, FailedTestCasesStatus.FULL).build();
// Check that only //package:name is printed.
AnsiTerminalPrinter printer = Mockito.mock(AnsiTerminalPrinter.class);
TestSummaryPrinter.print(summary, printer, true, true);
verify(printer).print(contains("//package:name"));
}
use of com.google.devtools.build.lib.view.test.TestStatus.TestCase in project bazel by bazelbuild.
the class TestSummaryTest method testMessageShownForPartialResults.
@Test
public void testMessageShownForPartialResults() throws Exception {
ImmutableList<TestCase> testCases = ImmutableList.of(newDetail("orange", TestCase.Status.FAILED, 1500L));
TestSummary summary = createTestSummaryWithDetails(BlazeTestStatus.FAILED, testCases, FailedTestCasesStatus.PARTIAL);
AnsiTerminalPrinter printer = Mockito.mock(AnsiTerminalPrinter.class);
TestSummaryPrinter.print(summary, printer, true, true);
verify(printer).print(contains("//package:name"));
verify(printer).print(find("FAILED.*orange"));
verify(printer).print(contains("incomplete"));
}
use of com.google.devtools.build.lib.view.test.TestStatus.TestCase in project bazel by bazelbuild.
the class TestSummaryTest method testMessageShownWhenTestCasesMissing.
@Test
public void testMessageShownWhenTestCasesMissing() throws Exception {
ImmutableList<TestCase> emptyList = ImmutableList.of();
TestSummary summary = createTestSummaryWithDetails(BlazeTestStatus.FAILED, emptyList, FailedTestCasesStatus.NOT_AVAILABLE);
AnsiTerminalPrinter printer = Mockito.mock(AnsiTerminalPrinter.class);
TestSummaryPrinter.print(summary, printer, true, true);
verify(printer).print(contains("//package:name"));
verify(printer).print(contains("not available"));
}
use of com.google.devtools.build.lib.view.test.TestStatus.TestCase in project bazel by bazelbuild.
the class TestSummaryTest method testTestCaseNamesShownWhenNeeded.
@Test
public void testTestCaseNamesShownWhenNeeded() throws Exception {
TestCase detailPassed = newDetail("strawberry", TestCase.Status.PASSED, 1000L);
TestCase detailFailed = newDetail("orange", TestCase.Status.FAILED, 1500L);
TestSummary summaryPassed = createTestSummaryWithDetails(BlazeTestStatus.PASSED, Arrays.asList(detailPassed));
TestSummary summaryFailed = createTestSummaryWithDetails(BlazeTestStatus.FAILED, Arrays.asList(detailPassed, detailFailed));
assertEquals(BlazeTestStatus.FAILED, summaryFailed.getStatus());
AnsiTerminalPrinter printerPassed = Mockito.mock(AnsiTerminalPrinter.class);
TestSummaryPrinter.print(summaryPassed, printerPassed, true, true);
verify(printerPassed).print(contains("//package:name"));
AnsiTerminalPrinter printerFailed = Mockito.mock(AnsiTerminalPrinter.class);
TestSummaryPrinter.print(summaryFailed, printerFailed, true, true);
verify(printerFailed).print(contains("//package:name"));
verify(printerFailed).print(find("FAILED.*orange *\\(1\\.5"));
}
Aggregations