RetryPlugin implements Aggregator { @SuppressWarnings({"PMD.AvoidLiteralsInIfCondition", "PMD.AvoidInstantiatingObjectsInLoops"}) @Override public void aggregate(final Configuration configuration, final List<LaunchResults> launchesResults, final Path outputDirectory) { final Map<String, List<TestResult>> byHistory = launchesResults.stream() .flatMap(results -> results.getAllResults().stream()) .filter(result -> Objects.nonNull(result.getHistoryId())) .collect(Collectors.toMap(TestResult::getHistoryId, Arrays::asList, this::merge)); byHistory.forEach((historyId, results) -> findLatest(results).ifPresent(addRetries(results))); }  @SuppressWarnings({"PMD.AvoidLiteralsInIfCondition", "PMD.AvoidInstantiatingObjectsInLoops"}) @Override void aggregate(final Configuration configuration,
                          final List<LaunchResults> launchesResults,
                          final Path outputDirectory); static final String RETRY_BLOCK_NAME; }
@Test void shouldMergeRetriesTestResults() { String historyId = UUID.randomUUID().toString(); List<LaunchResults> launchResultsList = createSingleLaunchResults( createTestResult(FIRST_RESULT, historyId, 1L, 9L), createTestResult(SECOND_RESULT, historyId, 11L, 19L), createTestResult(LAST_RESULT, historyId, 21L, 29L) ); retryPlugin.aggregate(null, launchResultsList, null); Set<TestResult> results = launchResultsList.get(0).getAllResults(); assertThat(results).as("test retries") .filteredOn(TestResult::isHidden) .extracting(TestResult::getName) .containsExactlyInAnyOrder(FIRST_RESULT, SECOND_RESULT); TestResult lastResult = results.stream() .filter(r -> !r.isHidden()).findFirst().orElseGet(null); assertThat(Collections.singletonList(lastResult)) .as("latest test result") .extracting(TestResult::getName, TestResult::isHidden, TestResult::isFlaky) .containsExactlyInAnyOrder(tuple(LAST_RESULT, false, true)); assertThat(results).as("test results with retries block") .filteredOn(result -> result.hasExtraBlock(RETRY_BLOCK_NAME)) .hasSize(1); List<RetryItem> retries = lastResult.getExtraBlock(RETRY_BLOCK_NAME); assertThat(retries).as("test results retries block") .isNotNull() .hasSize(2); }
@Test void shouldNotMergeOtherTestResults() { String firstHistoryId = UUID.randomUUID().toString(); String secondHistoryId = UUID.randomUUID().toString(); List<LaunchResults> launchResultsList = createSingleLaunchResults( createTestResult(FIRST_RESULT, firstHistoryId, 1L, 9L), createTestResult(SECOND_RESULT, secondHistoryId, 11L, 19L) ); retryPlugin.aggregate(null, launchResultsList, null); Set<TestResult> results = launchResultsList.get(0).getAllResults(); assertThat(results).as("test results") .filteredOn(TestResult::isHidden) .hasSize(0); assertThat(results).as("test results with retries block") .flatExtracting(result -> result.getExtraBlock(RETRY_BLOCK_NAME)) .hasSize(0); }
@Test void shouldSkipHiddenResults() { String historyId = UUID.randomUUID().toString(); List<LaunchResults> launchResultsList = createSingleLaunchResults( createTestResult(FIRST_RESULT, historyId, 1L, 9L), createTestResult(SECOND_RESULT, historyId, 11L, 19L), createTestResult(LAST_RESULT, historyId, 21L, 29L).setHidden(true) ); retryPlugin.aggregate(null, launchResultsList, null); Set<TestResult> results = launchResultsList.get(0).getAllResults(); assertThat(results) .filteredOn(TestResult::isHidden) .extracting(TestResult::getName) .containsExactlyInAnyOrder(FIRST_RESULT, LAST_RESULT); assertThat(results) .filteredOn(result -> !result.isHidden()) .extracting(TestResult::getName, TestResult::isFlaky) .containsExactlyInAnyOrder(tuple(SECOND_RESULT, true)); }
@Test void shouldNotMarkLatestAsFlakyIfRetriesArePassed() { String historyId = UUID.randomUUID().toString(); List<LaunchResults> launchResultsList = createSingleLaunchResults( createTestResult(FIRST_RESULT, historyId, 1L, 9L).setStatus(Status.PASSED), createTestResult(SECOND_RESULT, historyId, 11L, 19L).setStatus(Status.PASSED) ); retryPlugin.aggregate(null, launchResultsList, null); Set<TestResult> results = launchResultsList.get(0).getAllResults(); assertThat(results) .filteredOn(TestResult::isHidden) .extracting(TestResult::getName) .containsExactlyInAnyOrder(FIRST_RESULT); assertThat(results) .filteredOn(result -> !result.isHidden()) .extracting(TestResult::getName, TestResult::isFlaky) .containsExactlyInAnyOrder(tuple(SECOND_RESULT, false)); }
@Test void shouldNotMarkLatestAsFlakyIfRetriesSkipped() { String historyId = UUID.randomUUID().toString(); List<LaunchResults> launchResultsList = createSingleLaunchResults( createTestResult(FIRST_RESULT, historyId, 1L, 9L).setStatus(Status.SKIPPED), createTestResult(SECOND_RESULT, historyId, 11L, 19L).setStatus(Status.PASSED), createTestResult(LAST_RESULT, historyId, 12L, 20L).setHidden(true).setStatus(Status.PASSED) ); retryPlugin.aggregate(null, launchResultsList, null); Set<TestResult> results = launchResultsList.get(0).getAllResults(); assertThat(results) .filteredOn(TestResult::isHidden) .extracting(TestResult::getName) .containsExactlyInAnyOrder(FIRST_RESULT, LAST_RESULT); assertThat(results) .filteredOn(result -> !result.isHidden()) .extracting(TestResult::getName, TestResult::isFlaky) .containsExactlyInAnyOrder(tuple(SECOND_RESULT, false)); }