1

We have implement retry on our testrun, occours that retry only run on single thread. Is there any way we can run all retry testcases on parallel mode?

Testrunner.java

  void Runner() {
        int threadCount = getThreadCountProperty();
        Results results = karateRunner(FEATURE_TEST_PATH, ignoredTags, REPORT_DIR).parallel(threadCount);
        List<ScenarioResult> failed = results.getScenarioResults().filter(sr -> sr.isFailed()).collect(Collectors.toList());

        if (failed.isEmpty()) {
            KARATE_LOGGER.info("No failed case found");
        } else {
            KARATE_LOGGER.info(String.format("Found %d failed case(s)", failed.size()));
            for (ScenarioResult f : failed) {
                Scenario retryScenario = f.getScenario();
                try {
                    for (int i = 0; i < MAX_RETRY; i++) {
                        KARATE_LOGGER.info(String.format("Retry Attempt: %d - %s", i, retryScenario.getName()));
                        ScenarioResult retryResult = results.getSuite().retryScenario(retryScenario);
                        if (!retryResult.isFailed()) {
                            assertFalse(retryResult.isFailed());
                            results = results.getSuite().updateResults(retryResult);
                            break;
                        }
                    }
                } catch (NullPointerException e) {
                    System.err.println("No more testcases found");
                }
                finally {
                    /**
                     * Remove this remark to generate html cucumber-report
                     */
                    // generateReport(results.getReportDir());
                    assertEquals(0, results.getFailCount(), results.getErrorMessages());
                }
            }
        }
    }

enter image description here is there any way we can make it distributed to all threads?

JudiHaram
  • 23
  • 2
  • you can try using a java `ThreadExecutor` to run the loop. else this is something karate does not support yet, code contributions are welcome. we recommend that you focus on getting tests to not be flaky – Peter Thomas Mar 17 '23 at 04:30
  • 99% of our failed cases were actually caused by API performance(response time out). Thanks, I will try the ThreadExecutor. – JudiHaram Mar 20 '23 at 03:21
  • 1
    ok, please be aware that there is a `retry until` keyword in karate - so if your main issue is an API that just takes time to refect an underlying data change, it might solve your problem: https://stackoverflow.com/a/55823180/143475 – Peter Thomas Mar 20 '23 at 04:47

0 Answers0