From 6a120644211c79be5557d394c7a06f411c3f0071 Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Thu, 22 Sep 2022 12:53:51 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=9C=BA=E6=99=AF=E5=A4=B1=E8=B4=A5=E9=87=8D?= =?UTF-8?q?=E8=AF=95=E5=A4=9A=E6=AC=A1=E5=90=8E=E6=8A=A5=E5=91=8A=E7=8A=B6?= =?UTF-8?q?=E6=80=81=E7=BB=9F=E8=AE=A1=E9=94=99=E8=AF=AF=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1017152 --user=赵勇 【测试计划】接口场景失败重试,重试过程中成功了,但是场景结果是失败 https://www.tapd.cn/55049933/s/1250032 --- .../api/service/ApiScenarioReportService.java | 30 +++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java b/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java index 088a466246..d3294297eb 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java @@ -33,6 +33,7 @@ import io.metersphere.service.UserService; import io.metersphere.track.dto.PlanReportCaseDTO; import io.metersphere.track.dto.UiRunModeConfigDTO; 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; @@ -543,7 +544,7 @@ public class ApiScenarioReportService { String custom = "customCommand"; if (report.getExecuteType().equals(ExecuteType.Debug.name()) && report.getReportType().equals(ReportTypeConstants.UI_INDEPENDENT.name()) && - !StringUtils.equalsIgnoreCase(scenario.getScenarioType(), custom) + !StringUtils.equalsIgnoreCase(scenario.getScenarioType(), custom) ) { return false; } @@ -948,6 +949,29 @@ public class ApiScenarioReportService { return report; } + public List filterRetryResults(List results) { + List list = new LinkedList<>(); + if (CollectionUtils.isNotEmpty(results)) { + Map> resultMap = results.stream().collect(Collectors.groupingBy(RequestResult::getResourceId)); + resultMap.forEach((k, v) -> { + if (CollectionUtils.isNotEmpty(v)) { + // 校验是否含重试结果 + List 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; + } + /** * 返回正确的报告状态 * @@ -959,7 +983,9 @@ public class ApiScenarioReportService { // 资源池执行整体传输失败,单条传输内容,获取资源池执行统计的状态 return String.valueOf(dto.getArbitraryData().get("REPORT_STATUS")); } - long errorSize = dto.getRequestResults().stream().filter(requestResult -> + // 过滤掉重试结果后进行统计 + List 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 ->