Search in sources :

Example 1 with TestCase

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);
        }
    }
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) TestResultData(com.google.devtools.build.lib.view.test.TestStatus.TestResultData) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) IOException(java.io.IOException) WorkRequest(com.google.devtools.build.lib.worker.WorkerProtocol.WorkRequest) Executor(com.google.devtools.build.lib.actions.Executor) HashCode(com.google.common.hash.HashCode) TestCase(com.google.devtools.build.lib.view.test.TestStatus.TestCase) WorkResponse(com.google.devtools.build.lib.worker.WorkerProtocol.WorkResponse) TestExecException(com.google.devtools.build.lib.actions.TestExecException)

Example 2 with TestCase

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"));
}
Also used : AnsiTerminalPrinter(com.google.devtools.build.lib.util.io.AnsiTerminalPrinter) TestCase(com.google.devtools.build.lib.view.test.TestStatus.TestCase) Test(org.junit.Test)

Example 3 with TestCase

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"));
}
Also used : AnsiTerminalPrinter(com.google.devtools.build.lib.util.io.AnsiTerminalPrinter) TestCase(com.google.devtools.build.lib.view.test.TestStatus.TestCase) Test(org.junit.Test)

Example 4 with TestCase

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"));
}
Also used : AnsiTerminalPrinter(com.google.devtools.build.lib.util.io.AnsiTerminalPrinter) TestCase(com.google.devtools.build.lib.view.test.TestStatus.TestCase) Test(org.junit.Test)

Example 5 with TestCase

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"));
}
Also used : AnsiTerminalPrinter(com.google.devtools.build.lib.util.io.AnsiTerminalPrinter) TestCase(com.google.devtools.build.lib.view.test.TestStatus.TestCase) Test(org.junit.Test)

Aggregations

TestCase (com.google.devtools.build.lib.view.test.TestStatus.TestCase)9 AnsiTerminalPrinter (com.google.devtools.build.lib.util.io.AnsiTerminalPrinter)6 Test (org.junit.Test)6 Path (com.google.devtools.build.lib.vfs.Path)3 IOException (java.io.IOException)3 Executor (com.google.devtools.build.lib.actions.Executor)2 TestExecException (com.google.devtools.build.lib.actions.TestExecException)2 TestResultData (com.google.devtools.build.lib.view.test.TestStatus.TestResultData)2 HashCode (com.google.common.hash.HashCode)1 EnvironmentalExecException (com.google.devtools.build.lib.actions.EnvironmentalExecException)1 ExecException (com.google.devtools.build.lib.actions.ExecException)1 SpawnActionContext (com.google.devtools.build.lib.actions.SpawnActionContext)1 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)1 BlazeTestStatus (com.google.devtools.build.lib.view.test.TestStatus.BlazeTestStatus)1 Builder (com.google.devtools.build.lib.view.test.TestStatus.TestResultData.Builder)1 WorkRequest (com.google.devtools.build.lib.worker.WorkerProtocol.WorkRequest)1 WorkResponse (com.google.devtools.build.lib.worker.WorkerProtocol.WorkResponse)1 Closeable (java.io.Closeable)1 ArrayList (java.util.ArrayList)1 InOrder (org.mockito.InOrder)1