From 02062eee3e6e2d1e8199a2ce80c445cdbbfbf2d0 Mon Sep 17 00:00:00 2001 From: chenjianxing Date: Fri, 11 Nov 2022 10:35:03 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=B5=8B=E8=AF=95=E8=B7=9F=E8=B8=AA):=20?= =?UTF-8?q?=E5=BC=80=E6=BA=90=E7=94=A8=E6=88=B7=E6=B5=8B=E8=AF=95=E8=AE=A1?= =?UTF-8?q?=E5=88=92=E9=83=A8=E5=88=86=E6=93=8D=E4=BD=9C=E5=90=8E=E7=AB=AF?= =?UTF-8?q?=E6=9C=89=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plan/service/TestPlanReportService.java | 46 ++++++--------- .../plan/service/TestPlanService.java | 59 ++++++------------- 2 files changed, 35 insertions(+), 70 deletions(-) diff --git a/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanReportService.java b/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanReportService.java index ac806b51ff..c1d0e897f1 100644 --- a/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanReportService.java +++ b/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanReportService.java @@ -155,73 +155,61 @@ public class TestPlanReportService { // 测试计划报告各用例集合 List planReportCaseDTOS; + Set serviceIdSet = DiscoveryUtil.getServiceIdSet(); + if (testPlanExecuteReportDTO == null) { - try { + + if (serviceIdSet.contains(MicroServiceName.API_TEST)) { // 接口用例 planReportCaseDTOS = planTestPlanApiCaseService.selectStatusForPlanReport(planId); TestPlanStatusCalculator.buildStatusResultMap(planReportCaseDTOS, statusResultMap, report, ApiReportStatus.SUCCESS.name()); - } catch (Exception e) { - LogUtil.error(e); - } - - try { // 场景用例 planReportCaseDTOS = planTestPlanScenarioCaseService.selectStatusForPlanReport(planId); TestPlanStatusCalculator.buildStatusResultMap(planReportCaseDTOS, statusResultMap, report, ApiReportStatus.SUCCESS.name()); - } catch (Exception e) { - LogUtil.error(e); } - try { + + if (serviceIdSet.contains(MicroServiceName.PERFORMANCE_TEST)) { // 性能用例 planReportCaseDTOS = planTestPlanLoadCaseService.selectStatusForPlanReport(planId); TestPlanStatusCalculator.buildStatusResultMap(planReportCaseDTOS, statusResultMap, report, ApiReportStatus.SUCCESS.name()); - } catch (Exception e) { - LogUtil.error(e); } } else { // 报告 ID 集合 List reportIds = null; - if (MapUtils.isNotEmpty(testPlanExecuteReportDTO.getTestPlanApiCaseIdAndReportIdMap())) { - // 接口用例 - try { + // 接口用例 + if (serviceIdSet.contains(MicroServiceName.API_TEST)) { + if (MapUtils.isNotEmpty(testPlanExecuteReportDTO.getTestPlanApiCaseIdAndReportIdMap())) { reportIds = new ArrayList<>(testPlanExecuteReportDTO.getTestPlanApiCaseIdAndReportIdMap().values()); planReportCaseDTOS = planApiDefinitionExecResultService.selectForPlanReport(reportIds); TestPlanStatusCalculator.buildStatusResultMap(planReportCaseDTOS, statusResultMap, report, ApiReportStatus.SUCCESS.name()); - } catch (Exception e) { - LogUtil.error(e); } - } - if (MapUtils.isNotEmpty(testPlanExecuteReportDTO.getTestPlanScenarioIdAndReportIdMap())) { - try { + if (MapUtils.isNotEmpty(testPlanExecuteReportDTO.getTestPlanScenarioIdAndReportIdMap())) { // 场景用例 reportIds = new ArrayList<>(testPlanExecuteReportDTO.getTestPlanScenarioIdAndReportIdMap().values()); planReportCaseDTOS = planApiScenarioReportService.selectForPlanReport(reportIds); TestPlanStatusCalculator.buildStatusResultMap(planReportCaseDTOS, statusResultMap, report, ApiReportStatus.SUCCESS.name()); - } catch (Exception e) { - LogUtil.error(e); } } - if (MapUtils.isNotEmpty(testPlanExecuteReportDTO.getTestPlanUiScenarioIdAndReportIdMap())) { - try { + + if (serviceIdSet.contains(MicroServiceName.UI_TEST)) { + if (MapUtils.isNotEmpty(testPlanExecuteReportDTO.getTestPlanUiScenarioIdAndReportIdMap())) { // 场景用例 reportIds = new ArrayList<>(testPlanExecuteReportDTO.getTestPlanUiScenarioIdAndReportIdMap().values()); planReportCaseDTOS = planApiScenarioReportService.selectForPlanReport(reportIds); TestPlanStatusCalculator.buildStatusResultMap(planReportCaseDTOS, statusResultMap, report, ApiReportStatus.SUCCESS.name()); - } catch (Exception e) { - LogUtil.error(e); } } - if (MapUtils.isNotEmpty(testPlanExecuteReportDTO.getTestPlanLoadCaseIdAndReportIdMap())) { - try { + + if (serviceIdSet.contains(MicroServiceName.PERFORMANCE_TEST)) { + if (MapUtils.isNotEmpty(testPlanExecuteReportDTO.getTestPlanLoadCaseIdAndReportIdMap())) { // 性能用例 reportIds = new ArrayList<>(testPlanExecuteReportDTO.getTestPlanLoadCaseIdAndReportIdMap().values()); planReportCaseDTOS = planLoadTestReportService.getPlanReportCaseDTO(reportIds); TestPlanStatusCalculator.buildStatusResultMap(planReportCaseDTOS, statusResultMap, report, ApiReportStatus.SUCCESS.name()); - } catch (Exception e) { - LogUtil.error(e); } } + } report.setExecuteRate(0.0); report.setPassRate(0.0); diff --git a/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanService.java b/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanService.java index 44f193b1ea..de538fc794 100644 --- a/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanService.java +++ b/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanService.java @@ -480,25 +480,18 @@ public class TestPlanService { public void checkStatus(String testPlanId) { // 检查执行结果,自动更新计划状态 List statusList = new ArrayList<>(); statusList.addAll(extTestPlanTestCaseMapper.getExecResultByPlanId(testPlanId)); - try { + + Set serviceIdSet = DiscoveryUtil.getServiceIdSet(); + + if (serviceIdSet.contains(MicroServiceName.API_TEST)) { statusList.addAll(planTestPlanApiCaseService.getExecResultByPlanId(testPlanId)); - } catch (MSException e) { - LogUtil.error(e); - } - try { statusList.addAll(planTestPlanScenarioCaseService.getExecResultByPlanId(testPlanId)); - } catch (MSException e) { - LogUtil.error(e); } - try { + if (serviceIdSet.contains(MicroServiceName.PERFORMANCE_TEST)) { statusList.addAll(planTestPlanLoadCaseService.getExecResultByPlanId(testPlanId)); - } catch (MSException e) { - LogUtil.error(e); } - try { + if (serviceIdSet.contains(MicroServiceName.UI_TEST)) { statusList.addAll(planTestPlanUiScenarioCaseService.getExecResultByPlanId(testPlanId)); - } catch (MSException e) { - LogUtil.error(e); } TestPlanWithBLOBs testPlanWithBLOBs = testPlanMapper.selectByPrimaryKey(testPlanId); @@ -638,12 +631,13 @@ public class TestPlanService { } private void startRelevance(PlanCaseRelevanceRequest request, List apiCaseIds, List scenarioIds, List performanceIds) { - try { - relevanceTestCaseTest(apiCaseIds, request.getPlanId(), planTestPlanApiCaseService::relevanceByTestIds); - relevanceTestCaseTest(scenarioIds, request.getPlanId(), planTestPlanScenarioCaseService::relevanceByTestIds); - relevanceTestCaseTest(performanceIds, request.getPlanId(), planTestPlanLoadCaseService::relevanceByTestIds); - } catch (MSException e) { - LogUtil.error(e); + Set serviceIdSet = DiscoveryUtil.getServiceIdSet(); + if (serviceIdSet.contains(MicroServiceName.API_TEST)) { + planTestPlanApiCaseService.relevanceByTestIds(apiCaseIds, request.getPlanId()); + planTestPlanScenarioCaseService.relevanceByTestIds(scenarioIds, request.getPlanId()); + } + if (serviceIdSet.contains(MicroServiceName.PERFORMANCE_TEST)) { + planTestPlanLoadCaseService.relevanceByTestIds(performanceIds, request.getPlanId()); } } @@ -661,14 +655,6 @@ public class TestPlanService { } } - public void relevanceTestCaseTest(List ids, String planId, BiConsumer, String> relevanceByTestIds) { - try { - relevanceByTestIds.accept(ids, planId); - } catch (MSException e) { - LogUtil.error(e); - } - } - public List recentTestPlans(String projectId) { return extTestPlanMapper.listRecent(SessionUtils.getUserId(), projectId); } @@ -908,6 +894,7 @@ public class TestPlanService { } } } + /** * 将测试计划运行时的triggerMode转化为性能测试中辨别更明确的值 * @@ -1145,12 +1132,6 @@ public class TestPlanService { } sqlSession.flushStatements(); - try { - planTestPlanApiCaseService.copyPlan(sourcePlanId, targetPlanId); - } catch (Exception e) { - LogUtil.error(e); - } - Set serviceIdSet = DiscoveryUtil.getServiceIdSet(); if (serviceIdSet.contains(MicroServiceName.API_TEST)) { @@ -1269,11 +1250,9 @@ public class TestPlanService { request.setConfig(config); request.setPlanId(planId); request.setSaveResponse(saveResponse); - try { + if (DiscoveryUtil.hasService(MicroServiceName.API_TEST)) { ApiPlanReportDTO apiReport = planTestPlanScenarioCaseService.getApiReport(request); BeanUtils.copyBean(report, apiReport); - } catch (MSException e) { - LogUtil.error(e); } } @@ -1282,11 +1261,9 @@ public class TestPlanService { request.setConfig(config); request.setPlanId(planId); request.setSaveResponse(saveResponse); - try { + if (DiscoveryUtil.hasService(MicroServiceName.PERFORMANCE_TEST)) { LoadPlanReportDTO loadPlanReport = planTestPlanLoadCaseService.getLoadReport(request); BeanUtils.copyBean(report, loadPlanReport); - } catch (MSException e) { - LogUtil.error(e); } } @@ -1562,11 +1539,11 @@ public class TestPlanService { .flatMap(Collection::stream) .distinct() .collect(Collectors.toList()); - if (CollectionUtils.isNotEmpty(result)){ + if (CollectionUtils.isNotEmpty(result)) { envMap.put(projectId, result); } } else { - if (CollectionUtils.isNotEmpty(scenarioEnv.get(projectId))){ + if (CollectionUtils.isNotEmpty(scenarioEnv.get(projectId))) { envMap.put(projectId, scenarioEnv.get(projectId)); } }