private TestSummary.Builder markIncomplete(TestSummary.Builder summaryBuilder) { // TODO(bazel-team): (2010) Make NotRunTestResult support both tests failed to built and // tests with no status and post it here. TestSummary summary = summaryBuilder.peek(); BlazeTestStatus status = summary.getStatus(); if (status != BlazeTestStatus.NO_STATUS) { status = aggregateStatus(status, BlazeTestStatus.INCOMPLETE); } return summaryBuilder.setStatus(status); }
/** * Helper for differential analysis which aggregates the TestSummary for an individual target, * reporting runs on the EventBus if necessary. */ private TestSummary.Builder aggregateAndReportSummary( ConfiguredTarget testTarget, AggregatingTestListener listener) { // If already reported by the listener, no work remains for this target. TestSummary.Builder summary = listener.getCurrentSummary(testTarget); Label testLabel = testTarget.getLabel(); Preconditions.checkNotNull( summary, "%s did not complete test filtering, but has a test result", testLabel); if (listener.targetReported(testTarget)) { return summary; } Collection<Artifact> incompleteRuns = listener.getIncompleteRuns(testTarget); Map<Artifact, TestResult> statusMap = listener.getStatusMap(); // We will get back multiple TestResult instances if test had to be retried several // times before passing. Sharding and multiple runs of the same test without retries // will be represented by separate artifacts and will produce exactly one TestResult. for (Artifact testStatus : TestProvider.getTestStatusArtifacts(testTarget)) { // When a build is interrupted ( eg. a broken target with --nokeep_going ) runResult could // be null for an unrelated test because we were not able to even try to execute the test. // In that case, for tests that were previously passing we return null ( == NO STATUS), // because checking if the cached test target is up-to-date would require running the // dependency checker transitively. TestResult runResult = statusMap.get(testStatus); boolean isIncompleteRun = incompleteRuns.contains(testStatus); if (runResult == null) { summary = markIncomplete(summary); } else if (isIncompleteRun) { // Only process results which were not recorded by the listener. boolean newlyFetched = !statusMap.containsKey(testStatus); summary = incrementalAnalyze(summary, runResult); if (newlyFetched) { eventBus.post(runResult); } Preconditions.checkState( listener.getIncompleteRuns(testTarget).contains(testStatus) == isIncompleteRun, "TestListener changed in differential analysis. Ensure it isn't still registered."); } } // The target was not posted by the listener and must be posted now. eventBus.post(summary.build()); return summary; }
TestSummary.Builder markUnbuilt(TestSummary.Builder summary, boolean blazeHalted) { BlazeTestStatus runStatus = blazeHalted ? BlazeTestStatus.BLAZE_HALTED_BEFORE_TESTING : (executionOptions.testCheckUpToDate ? BlazeTestStatus.NO_STATUS : BlazeTestStatus.FAILED_TO_BUILD); return summary.setStatus(runStatus); }
/** * Incrementally updates a TestSummary given an existing summary and a new TestResult. Only call * on built targets. * * @param summaryBuilder Existing unbuilt test summary associated with a target. * @param result New test result to aggregate into the summary. * @return The updated TestSummary. */ public TestSummary.Builder incrementalAnalyze( TestSummary.Builder summaryBuilder, TestResult result) { // Cache retrieval should have been performed already. Preconditions.checkNotNull(result); Preconditions.checkNotNull(summaryBuilder); TestSummary existingSummary = Preconditions.checkNotNull(summaryBuilder.peek()); TransitiveInfoCollection target = existingSummary.getTarget(); Preconditions.checkNotNull(target, "The existing TestSummary must be associated with a target"); BlazeTestStatus status = existingSummary.getStatus(); int numCached = existingSummary.numCached(); int numLocalActionCached = existingSummary.numLocalActionCached(); // If a test was neither cached locally nor remotely we say action was taken. if (!(result.isCached() || result.getData().getRemotelyCached())) { summaryBuilder.setActionRan(true); } else { numCached++; } if (result.isCached()) { numLocalActionCached++; } PathFragment coverageData = result.getCoverageData(); if (coverageData != null) { summaryBuilder.addCoverageFiles( Collections.singletonList(execRoot.getRelative(coverageData))); } if (!executionOptions.runsPerTestDetectsFlakes) { status = aggregateStatus(status, result.getData().getStatus()); } else { int shardNumber = result.getShardNum(); int runsPerTestForLabel = target.getProvider(TestProvider.class).getTestParams().getRuns(); List<BlazeTestStatus> singleShardStatuses = summaryBuilder.addShardStatus(shardNumber, result.getData().getStatus()); if (singleShardStatuses.size() == runsPerTestForLabel) { BlazeTestStatus shardStatus = BlazeTestStatus.NO_STATUS; int passes = 0; for (BlazeTestStatus runStatusForShard : singleShardStatuses) { shardStatus = aggregateStatus(shardStatus, runStatusForShard); if (TestResult.isBlazeTestStatusPassed(shardStatus)) { passes++; } } // Under the RunsPerTestDetectsFlakes option, return flaky if 1 <= p < n shards pass. // If all results pass or fail, aggregate the passing/failing shardStatus. if (passes == 0 || passes == runsPerTestForLabel) { status = aggregateStatus(status, shardStatus); } else { status = aggregateStatus(status, BlazeTestStatus.FLAKY); } } } List<Path> passed = new ArrayList<>(); if (result.getData().hasPassedLog()) { passed.add( result .getTestAction() .getTestLog() .getPath() .getRelative(result.getData().getPassedLog())); } List<Path> failed = new ArrayList<>(); for (String path : result.getData().getFailedLogsList()) { failed.add(result.getTestAction().getTestLog().getPath().getRelative(path)); } summaryBuilder .addTestTimes(result.getData().getTestTimesList()) .addPassedLogs(passed) .addFailedLogs(failed) .addWarnings(result.getData().getWarningList()) .collectFailedTests(result.getData().getTestCase()) .setRanRemotely(result.getData().getIsRemoteStrategy()); List<String> warnings = new ArrayList<>(); if (status == BlazeTestStatus.PASSED && shouldEmitTestSizeWarningInSummary( summaryOptions.testVerboseTimeoutWarnings, warnings, result.getData().getTestProcessTimesList(), target)) { summaryBuilder.setWasUnreportedWrongSize(true); } return summaryBuilder .setStatus(status) .setNumCached(numCached) .setNumLocalActionCached(numLocalActionCached) .addWarnings(warnings); }