Open ericdriggs opened 4 months ago
peter has already mentioned it here https://github.com/karatelabs/karate/blob/develop/karate-core/src/test/java/com/intuit/karate/core/retry/RetryTest.java#L35
i++ will make it continues loop without break; ideally you would want to run it once
@sadiqkassamali The example in the code shows a single retry for a single test. The example I provided is a drop-in function which provides multiple retries with parallel execution.
i am doing this this way.
List
try {
boolean rerun = true;
while(rerun)
if (!failed.isEmpty()) {
log.info("Fail size: + " + failed.size());
log.info("May have found failures for Rerun..checking");
for (int i = 0; i < failed.size(); i++) {
log.info("Total number of test case that failed, which will be rerun: " + failed.size());
Scenario scenario = failed.get(i).getScenario();
ScenarioResult sr = results.getSuite().retryScenario(scenario);
results = results.getSuite().updateResults(sr);
collector.checkThat(results.getFailCount(), equalTo(0));
rerun = false;
break;
}
} else {
log.info("Fail size: + " + failed.size());
log.info("Wow No Failures in the first run");
collector.checkThat(results.getFailCount(), equalTo(0));
rerun = false;
break;
}
} catch (Exception e) {
log.info("Error occurred Sending out email" + e.getMessage());
}
@sadiqkassamali
thanks for letting me know appreciate it, i stand corrected
@ericdriggs I would probably do:
// parallel retries
List<ScenarioResult> retriedResults =
failed.parallelStream()
.map(
scenarioResult -> {
Scenario scenario = scenarioResult.getScenario();
log.info("retrying scenario: {}, attempt", scenario.getName());
return suite.retryScenario(scenario);
})
.toList();
@sturose If you want a single retry
I'm not sure I follow. I'm just saying that instead of doing
Set<ScenarioResult> retriedResults = new ConcurrentSkipListSet<>();
//parallel retries
failed.parallelStream().forEach(scenarioResult -> {
Scenario scenario = scenarioResult.getScenario();
log.info("retrying scenario: {}, attempt: {}", scenario.getName(), attempt);
ScenarioResult sr = suite.retryScenario(scenario);
retriedResults.add(sr);
});
it reads a bit cleaner to do
// parallel retries
List<ScenarioResult> retriedResults =
failed.parallelStream()
.map(
scenarioResult -> {
Scenario scenario = scenarioResult.getScenario();
log.info("retrying scenario: {}, attempt", scenario.getName());
return suite.retryScenario(scenario);
})
.toList();
They are functionality equivalent.
tagging @bischoffdev since he maintains https://github.com/trivago/cluecumber - that supports generating reports for karate runs. I saw a recent update that improves support for when tests are re-tried - and perhaps Benjamin you have some experience with re-trying failed tests in karate ...
Purpose: documentation for rerunning failed tests
Use case: large suites of api tests with downstream service dependencies on other services have a high probability of failure. Option to rerun failed tests can make test management orders of magnitude easier and can be useful for distinguishing between logical errors and race conditions.
see:
Code examples