From 614433e39911baeb640b88b2004099b3fff368e0 Mon Sep 17 00:00:00 2001 From: song-tianyang Date: Tue, 30 Nov 2021 19:57:38 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=B5=8B=E8=AF=95=E8=AE=A1=E5=88=92?= =?UTF-8?q?=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E8=AE=A1=E5=88=92=E5=AE=9A=E6=97=B6=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E5=8F=96=E6=B6=88=E5=85=B3=E8=81=94=E8=B5=84=E6=BA=90?= =?UTF-8?q?=E6=B1=A0=E6=97=B6=E4=B8=8D=E7=94=9F=E6=95=88=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复测试计划定时任务取消关联资源池时不生效的问题,并在回调函数处增加log记录 --- .../api/service/ApiScenarioReportService.java | 17 ++++++---- .../track/service/TestPlanService.java | 33 ++++++++++++------- .../plan/components/ScheduleMaintain.vue | 5 +++ 3 files changed, 36 insertions(+), 19 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 a9033ea186..b3d90968e9 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java @@ -156,6 +156,7 @@ public class ApiScenarioReportService { public ApiScenarioReport editReport(ScenarioResult test, long startTime) { ApiScenarioReport report = apiScenarioReportMapper.selectByPrimaryKey(test.getName()); if (report == null) { + LogUtil.info("从缓存中获取场景报告:【" + test.getName() + "】"); report = MessageCache.scenarioExecResourceLock.get(test.getName()); } if (report != null) { @@ -169,6 +170,8 @@ public class ApiScenarioReportService { } MessageCache.scenarioExecResourceLock.remove(report.getId()); apiScenarioReportMapper.updateByPrimaryKeySelective(report); + } else { + LogUtil.error("未获取到场景报告!【" + test.getName() + "】"); } return report; } @@ -297,7 +300,7 @@ public class ApiScenarioReportService { } public ApiScenarioReport updateSchedulePlanCase(TestResult result, String runMode) { - + LogUtil.info("收到测试计划场景[" + result.getTestId() + "]的执行信息,开始保存"); ApiScenarioReport lastReport = null; List scenarioResultList = result.getScenarios(); @@ -307,7 +310,7 @@ public class ApiScenarioReportService { List reportIds = new ArrayList<>(); List scenarioIdList = new ArrayList<>(); Map scenarioAndErrorMap = new HashMap<>(); - Map planScenarioReportMap = new HashMap<>(); + Map planScenarioReportMap = new HashMap<>(); for (ScenarioResult scenarioResult : scenarioResultList) { // 存储场景报告 @@ -344,7 +347,7 @@ public class ApiScenarioReportService { report.setTestPlanScenarioId(planScenarioId); report.setEndTime(System.currentTimeMillis()); apiScenarioReportMapper.updateByPrimaryKeySelective(report); - planScenarioReportMap.put(planScenarioId,report.getId()); + planScenarioReportMap.put(planScenarioId, report.getId()); if (scenarioResult.getError() > 0) { @@ -406,7 +409,7 @@ public class ApiScenarioReportService { TestPlanReportExecuteCatch.updateApiTestPlanExecuteInfo(reportId, null, scenarioAndErrorMap, null); TestPlanReportExecuteCatch.updateTestPlanReport(reportId, null, planScenarioReportMap); } - + LogUtil.info("测试计划场景[" + result.getTestId() + "]保存结束"); return lastReport; } @@ -864,13 +867,13 @@ public class ApiScenarioReportService { } public Map getReportStatusByReportIds(Collection values) { - if(CollectionUtils.isEmpty(values)){ - return new HashMap<>(); + if (CollectionUtils.isEmpty(values)) { + return new HashMap<>(); } Map map = new HashMap<>(); List reportList = extApiScenarioReportMapper.selectStatusByIds(values); for (ApiScenarioReport report : reportList) { - map.put(report.getId(),report.getStatus()); + map.put(report.getId(), report.getStatus()); } return map; } diff --git a/backend/src/main/java/io/metersphere/track/service/TestPlanService.java b/backend/src/main/java/io/metersphere/track/service/TestPlanService.java index 24a1890a22..20f125516d 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestPlanService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestPlanService.java @@ -189,7 +189,7 @@ public class TestPlanService { @Resource private TestPlanFollowMapper testPlanFollowMapper; - private final ExecutorService executorService = Executors.newFixedThreadPool(20,new NamedThreadFactory("TestPlanService")); + private final ExecutorService executorService = Executors.newFixedThreadPool(20, new NamedThreadFactory("TestPlanService")); public synchronized TestPlan addTestPlan(AddTestPlanRequest testPlan) { if (getTestPlanByName(testPlan.getName()).size() > 0) { @@ -992,7 +992,7 @@ public class TestPlanService { testPlan.toHashTree(jmeterHashTree, testPlan.getHashTree(), new ParameterConfig()); String runMode = ApiRunMode.SCHEDULE_SCENARIO_PLAN.name(); // 调用执行方法 - jMeterService.runLocal(request.getId(),request.getConfig(), jmeterHashTree, request.getReportId(), runMode); + jMeterService.runLocal(request.getId(), request.getConfig(), jmeterHashTree, request.getReportId(), runMode); } return returnId; @@ -1076,8 +1076,17 @@ public class TestPlanService { runModeConfig.setReportType("iddReport"); runModeConfig.setEnvMap(new HashMap<>()); runModeConfig.setOnSampleError(false); - }else { - if(runModeConfig.getEnvMap() == null){ + } else { + try { + JSONObject runModeObj = JSONObject.parseObject(apiRunConfig); + if (runModeObj.containsKey("runWithinResourcePool") && !runModeObj.getBoolean("runWithinResourcePool")) { + runModeConfig.setResourcePoolId(null); + } + } catch (Exception e) { + LogUtil.error(e.getMessage()); + } + + if (runModeConfig.getEnvMap() == null) { runModeConfig.setEnvMap(new HashMap<>()); } } @@ -1097,11 +1106,11 @@ public class TestPlanService { } if (planApiCaseMap.size() > count) { testPlanReportService.finishReport(reportInfoDTO.getTestPlanReport()); - MSException.throwException("并发超过"+count+",数量过大,请重新选择!"); + MSException.throwException("并发超过" + count + ",数量过大,请重新选择!"); } if (planScenarioIdsMap.size() > count) { testPlanReportService.finishReport(reportInfoDTO.getTestPlanReport()); - MSException.throwException("并发超过"+count+",数量过大,请重新选择!"); + MSException.throwException("并发超过" + count + ",数量过大,请重新选择!"); } } extTestPlanMapper.updateActualEndTimeIsNullById(testPlanID); @@ -1148,14 +1157,14 @@ public class TestPlanService { } catch (Exception e) { e.printStackTrace(); } - performaneThreadIDMap.put(performanceRequest.getTestPlanLoadId(),reportId); + performaneThreadIDMap.put(performanceRequest.getTestPlanLoadId(), reportId); if (StringUtils.isNotEmpty(reportId)) { executePerformanceIdMap.put(caseID, TestPlanApiExecuteStatus.RUNNING.name()); } else { executePerformanceIdMap.put(caseID, TestPlanApiExecuteStatus.PREPARE.name()); } } - TestPlanReportExecuteCatch.updateTestPlanThreadInfo(planReportId,null,null,performaneThreadIDMap); + TestPlanReportExecuteCatch.updateTestPlanThreadInfo(planReportId, null, null, performaneThreadIDMap); if (!performaneReportIDMap.isEmpty()) { //性能测试时保存性能测试报告ID,在结果返回时用于捕捉并进行 testPlanReportService.updatePerformanceInfo(testPlanReport, performaneReportIDMap, triggerMode); @@ -1172,7 +1181,7 @@ public class TestPlanService { testPlanLog.info("ReportId[" + planReportId + "] start run. TestPlanID:[" + testPlanID + "]. Execute api :" + JSONObject.toJSONString(executeApiCaseIdMap) + "; Execute scenario:" + JSONObject.toJSONString(executeScenarioCaseIdMap) + "; Execute performance:" + JSONObject.toJSONString(executePerformanceIdMap)); TestPlanReportExecuteCatch.updateApiTestPlanExecuteInfo(planReportId, executeApiCaseIdMap, executeScenarioCaseIdMap, executePerformanceIdMap); //执行接口案例任务 - this.executeApiTestCase(triggerMode, planReportId,new ArrayList<>(planApiCaseMap.keySet()), runModeConfig); + this.executeApiTestCase(triggerMode, planReportId, new ArrayList<>(planApiCaseMap.keySet()), runModeConfig); //执行场景执行任务 this.executeScenarioCase(planReportId, testPlanID, projectID, runModeConfig, triggerMode, userId, planScenarioIdsMap); this.listenTaskExecuteStatus(planReportId); @@ -1702,7 +1711,7 @@ public class TestPlanService { } } - public void buildApiReport(TestPlanSimpleReportDTO report, JSONObject config, TestPlanExecuteInfo executeInfo,boolean isFinish) { + public void buildApiReport(TestPlanSimpleReportDTO report, JSONObject config, TestPlanExecuteInfo executeInfo, boolean isFinish) { if (MapUtils.isEmpty(executeInfo.getApiCaseExecInfo()) && MapUtils.isEmpty(executeInfo.getApiScenarioCaseExecInfo())) { return; } @@ -1712,12 +1721,12 @@ public class TestPlanService { if (checkReportConfig(config, "api", "all")) { if (MapUtils.isNotEmpty(executeInfo.getApiCaseExecInfo())) { // 接口 - apiAllCases = testPlanApiCaseService.getByApiExecReportIds(executeInfo.getApiCaseExecuteThreadMap(),isFinish); + apiAllCases = testPlanApiCaseService.getByApiExecReportIds(executeInfo.getApiCaseExecuteThreadMap(), isFinish); report.setApiAllCases(apiAllCases); } if (MapUtils.isNotEmpty(executeInfo.getApiScenarioCaseExecInfo())) { //场景 - scenarioAllCases = testPlanScenarioCaseService.getAllCases(executeInfo.getApiScenarioThreadMap(),isFinish); + scenarioAllCases = testPlanScenarioCaseService.getAllCases(executeInfo.getApiScenarioThreadMap(), isFinish); report.setScenarioAllCases(scenarioAllCases); } } diff --git a/frontend/src/business/components/track/plan/components/ScheduleMaintain.vue b/frontend/src/business/components/track/plan/components/ScheduleMaintain.vue index 42aaf8561e..23335ac491 100644 --- a/frontend/src/business/components/track/plan/components/ScheduleMaintain.vue +++ b/frontend/src/business/components/track/plan/components/ScheduleMaintain.vue @@ -165,6 +165,11 @@ export default { watch: { 'schedule.value'() { this.form.cronValue = this.schedule.value; + }, + 'runConfig.runWithinResourcePool'() { + if (!this.runConfig.runWithinResourcePool) { + this.runConfig.resourcePoolId = null; + } } }, data() {