From 1a017e82746f49b9ffc59bd1c94b291b448daf38 Mon Sep 17 00:00:00 2001 From: zhangdahai112 Date: Wed, 7 Sep 2022 12:55:58 +0800 Subject: [PATCH] =?UTF-8?q?fix(UI=20=E8=87=AA=E5=8A=A8=E5=8C=96)=20?= =?UTF-8?q?=E5=90=AB=E6=9C=89=E5=BE=AA=E7=8E=AF=E7=9A=84=E6=AD=A5=E9=AA=A4?= =?UTF-8?q?=E4=B8=80=E7=9B=B4=E4=B8=8D=E5=87=BA=E6=8A=A5=E5=91=8A=E7=BB=93?= =?UTF-8?q?=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1016617 --user=张大海 【UI测试】场景中含循环步骤-生成报告一直加载中 https://www.tapd.cn/55049933/s/1239868 --- .../api/service/utils/PassRateUtil.java | 33 ++++++++++++++----- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/service/utils/PassRateUtil.java b/backend/src/main/java/io/metersphere/api/service/utils/PassRateUtil.java index 08b58166e3..2e1fd1a7b1 100644 --- a/backend/src/main/java/io/metersphere/api/service/utils/PassRateUtil.java +++ b/backend/src/main/java/io/metersphere/api/service/utils/PassRateUtil.java @@ -36,7 +36,9 @@ public class PassRateUtil { } else { long successSize = requestResults.stream().filter(requestResult -> StringUtils.equalsIgnoreCase(requestResult.getStatus(), ScenarioStatus.Success.name())).count(); if (report.getReportType().startsWith(SystemConstants.TestTypeEnum.UI.name())) { - Map resultIdMap = requestResults.stream().collect(Collectors.toMap(r -> r.getResourceId(), r -> r.getStatus())); + //resourceId -> 结果列表 循环可能一个 resourceId 对应多个接口 + Map> resultResourceStatusMap = requestResults.stream().collect(Collectors.groupingBy(ApiScenarioReportResult::getResourceId)); + ApiScenarioReportStructureExample e = new ApiScenarioReportStructureExample(); e.createCriteria().andReportIdEqualTo(report.getId()); @@ -45,7 +47,7 @@ public class PassRateUtil { return "0"; } List stepList = JSONArray.parseArray(new String(apiScenarioReportStructures.get(0).getResourceTree(), StandardCharsets.UTF_8), StepTreeDTO.class); - successSize = getUISuccessSize(resultIdMap, stepList); + successSize = getUISuccessSize(resultResourceStatusMap, stepList); if (CollectionUtils.isEmpty(stepList)) { return "0"; @@ -64,20 +66,20 @@ public class PassRateUtil { * @param stepList * @return */ - private static long getUISuccessSize(Map resultIdMap, List stepList) { + private static long getUISuccessSize(Map> resultIdMap, List stepList) { AtomicLong atomicLong = new AtomicLong(); stepList.forEach(stepFather -> { stepFather.getChildren().forEach(step -> { if (StringUtils.equalsIgnoreCase(step.getType(), UISCENARIO_TYPE_NAME)) { - AtomicInteger failCount = new AtomicInteger(); + AtomicLong failCount = new AtomicLong(); getUIFailStepCount(resultIdMap, Optional.ofNullable(step.getChildren()).orElse(new ArrayList<>()), failCount); //复制或者嵌套场景的成功只算 1 次 if (failCount.get() == 0) { atomicLong.getAndAdd(1); } } else { - if (resultIdMap.containsKey(step.getResourceId()) && StringUtils.equalsIgnoreCase(resultIdMap.get(step.getResourceId()), ScenarioStatus.Success.name())) { - atomicLong.incrementAndGet(); + if (resultIdMap.containsKey(step.getResourceId()) && CollectionUtils.isNotEmpty(resultIdMap.get(step.getResourceId()))) { + calculateCount(resultIdMap, atomicLong, step, ScenarioStatus.Success.name()); } } }); @@ -94,18 +96,31 @@ public class PassRateUtil { * @param failCount * @return */ - private static void getUIFailStepCount(Map resultIdMap, List stepTrees, AtomicInteger failCount) { + private static void getUIFailStepCount(Map> resultIdMap, List stepTrees, AtomicLong failCount) { stepTrees.forEach(step -> { if (StringUtils.equalsIgnoreCase(step.getType(), UISCENARIO_TYPE_NAME)) { getUIFailStepCount(resultIdMap, Optional.ofNullable(step.getChildren()).orElse(new ArrayList<>()), failCount); } else { - if (resultIdMap.containsKey(step.getResourceId()) && StringUtils.equalsIgnoreCase(resultIdMap.get(step.getResourceId()), ScenarioStatus.Error.name())) { - failCount.incrementAndGet(); + if (resultIdMap.containsKey(step.getResourceId()) && CollectionUtils.isNotEmpty(resultIdMap.get(step.getResourceId()))) { + calculateCount(resultIdMap, failCount, step, ScenarioStatus.Fail.name()); } } }); } + private static void calculateCount(Map> resultIdMap, AtomicLong failCount, StepTreeDTO step, String status) { + List sameResourceIdResults = resultIdMap.get(step.getResourceId()); + if (StringUtils.equalsIgnoreCase(sameResourceIdResults.get(0).getStatus(), status)) { + failCount.incrementAndGet(); + + //计算完结果移除 + sameResourceIdResults.remove(0); + if (CollectionUtils.isEmpty(sameResourceIdResults)) { + resultIdMap.remove(step.getResourceId()); + } + } + } + /** * 计算总步骤数 *