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)); } }