fix(接口测试): 修复场景失败重试多次后报告状态统计错误问题

--bug=1017152 --user=赵勇 【测试计划】接口场景失败重试,重试过程中成功了,但是场景结果是失败 https://www.tapd.cn/55049933/s/1250032
This commit is contained in:
fit2-zhao 2022-09-22 13:55:21 +08:00 committed by fit2-zhao
parent 3545fc8b80
commit 1a7b958bba
1 changed files with 26 additions and 1 deletions

View File

@ -32,6 +32,7 @@ import io.metersphere.service.SystemParameterService;
import io.metersphere.service.UserService;
import io.metersphere.track.dto.PlanReportCaseDTO;
import io.metersphere.utils.LoggerUtil;
import io.metersphere.utils.RetryResultUtil;
import io.metersphere.xmind.utils.FileUtil;
import org.apache.commons.beanutils.BeanMap;
import org.apache.commons.collections4.CollectionUtils;
@ -873,12 +874,36 @@ public class ApiScenarioReportService {
return report;
}
public List<RequestResult> filterRetryResults(List<RequestResult> results) {
List<RequestResult> list = new LinkedList<>();
if (CollectionUtils.isNotEmpty(results)) {
Map<String, List<RequestResult>> resultMap = results.stream().collect(Collectors.groupingBy(RequestResult::getResourceId));
resultMap.forEach((k, v) -> {
if (CollectionUtils.isNotEmpty(v)) {
// 校验是否含重试结果
List<RequestResult> isRetryResults = v
.stream()
.filter(c -> StringUtils.isNotEmpty(c.getName()) && c.getName().startsWith(RetryResultUtil.RETRY_CN))
.collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(isRetryResults)) {
list.add(isRetryResults.get(isRetryResults.size() - 1));
} else {
// 成功的结果
list.addAll(v);
}
}
});
}
return list;
}
private String getStatus(ResultDTO dto) {
if (MapUtils.isNotEmpty(dto.getArbitraryData()) && dto.getArbitraryData().containsKey("REPORT_STATUS")) {
// 资源池执行整体传输失败单条传输内容获取资源池执行统计的状态
return String.valueOf(dto.getArbitraryData().get("REPORT_STATUS"));
}
long errorSize = dto.getRequestResults().stream().filter(requestResult ->
List<RequestResult> requestResults = filterRetryResults(dto.getRequestResults());
long errorSize = requestResults.stream().filter(requestResult ->
StringUtils.equalsIgnoreCase(requestResult.getStatus(), ScenarioStatus.Error.name())).count();
long errorReportResultSize = dto.getRequestResults().stream().filter(requestResult ->