From a793d72e4e8c6e1261e1a4f0c7fb1048ffd9a10d Mon Sep 17 00:00:00 2001 From: guoyuqi Date: Tue, 12 Apr 2022 17:35:10 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=B5=8B=E8=AF=95=E8=B7=9F=E8=B8=AA):=20?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E8=AE=A1=E5=88=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --user=郭雨琦 解决批量执行测试计划时在提示配置未保存的时候,测试计划还在执行的问题 点击测试计划进入用例页面增加对计划结束时间的校验 删除了一个没有调用的方法 --- .../track/service/TestPlanService.java | 87 +++---------------- 1 file changed, 11 insertions(+), 76 deletions(-) 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 9178bb2053..47ee28c837 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestPlanService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestPlanService.java @@ -496,42 +496,11 @@ public class TestPlanService { testPlanWithBLOBs.setStatus(TestPlanStatus.Completed.name()); this.editTestPlan(testPlanWithBLOBs); } else if (prepareNum == 0 && passNum + failNum == statusList.size()) { // 已结束 - testPlanWithBLOBs.setStatus(TestPlanStatus.Finished.name()); - editTestPlan(testPlanWithBLOBs); - } else if (prepareNum != 0) { // 进行中 - testPlanWithBLOBs.setStatus(TestPlanStatus.Underway.name()); - editTestPlan(testPlanWithBLOBs); - } - } - - public void checkStatus(TestPlanWithBLOBs testPlanWithBLOBs) { // 检查执行结果,自动更新计划状态 - List statusList = new ArrayList<>(); - statusList.addAll(extTestPlanTestCaseMapper.getExecResultByPlanId(testPlanWithBLOBs.getId())); - statusList.addAll(testPlanApiCaseService.getExecResultByPlanId(testPlanWithBLOBs.getId())); - statusList.addAll(testPlanScenarioCaseService.getExecResultByPlanId(testPlanWithBLOBs.getId())); - statusList.addAll(testPlanLoadCaseService.getStatus(testPlanWithBLOBs.getId())); - if (statusList.size() == 0) { // 原先status不是prepare, 但删除所有关联用例的情况 - testPlanWithBLOBs.setStatus(TestPlanStatus.Prepare.name()); - editTestPlan(testPlanWithBLOBs); - return; - } - int passNum = 0, prepareNum = 0, failNum = 0; - for (String res : statusList) { - if (StringUtils.equals(res, TestPlanTestCaseStatus.Pass.name()) - || StringUtils.equals(res, "success") - || StringUtils.equals(res, ScenarioStatus.Success.name())) { - passNum++; - } else if (res == null || StringUtils.equals(TestPlanStatus.Prepare.name(), res)) { - prepareNum++; - } else { - failNum++; + if(testPlanWithBLOBs.getPlannedEndTime() != null && testPlanWithBLOBs.getPlannedEndTime() > System.currentTimeMillis()){ + testPlanWithBLOBs.setStatus(TestPlanStatus.Completed.name()); + }else{ + testPlanWithBLOBs.setStatus(TestPlanStatus.Finished.name()); } - } - if (passNum == statusList.size()) { // 全部通过 - testPlanWithBLOBs.setStatus(TestPlanStatus.Completed.name()); - this.editTestPlan(testPlanWithBLOBs); - } else if (prepareNum == 0 && passNum + failNum == statusList.size()) { // 已结束 - testPlanWithBLOBs.setStatus(TestPlanStatus.Finished.name()); editTestPlan(testPlanWithBLOBs); } else if (prepareNum != 0) { // 进行中 testPlanWithBLOBs.setStatus(TestPlanStatus.Underway.name()); @@ -834,44 +803,6 @@ public class TestPlanService { return projectName; } - private String getTestPlanContext(TestPlan testPlan, String type) { - User user = userMapper.selectByPrimaryKey(testPlan.getCreator()); - Long startTime = testPlan.getPlannedStartTime(); - Long endTime = testPlan.getPlannedEndTime(); - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - String start = null; - String sTime = String.valueOf(startTime); - String eTime = String.valueOf(endTime); - if (!sTime.equals("null")) { - start = sdf.format(new Date(Long.parseLong(sTime))); - } else { - start = "未设置"; - } - String end = null; - if (!eTime.equals("null")) { - end = sdf.format(new Date(Long.parseLong(eTime))); - } else { - end = "未设置"; - } - String context = ""; - if (StringUtils.equals(NoticeConstants.Event.CREATE, type)) { - context = "测试计划任务通知:" + user.getName() + "创建的" + "'" + testPlan.getName() + "'" + "待开始,计划开始时间是:" + "'" + start + "'" + ";" + "计划结束时间是:" + "'" + end + "'" + " " + "请跟进"; - } else if (StringUtils.equals(NoticeConstants.Event.UPDATE, type)) { - String status = ""; - if (StringUtils.equals(TestPlanStatus.Underway.name(), testPlan.getStatus())) { - status = "进行中"; - } else if (StringUtils.equals(TestPlanStatus.Prepare.name(), testPlan.getStatus())) { - status = "未开始"; - } else if (StringUtils.equals(TestPlanStatus.Completed.name(), testPlan.getStatus())) { - status = "已完成"; - } - context = "测试计划任务通知:" + user.getName() + "创建的" + "'" + testPlan.getName() + "'" + "计划开始时间是:" + "'" + start + "'" + ";" + "计划结束时间是:" + "'" + end + "'" + " " + status; - } else if (StringUtils.equals(NoticeConstants.Event.DELETE, type)) { - context = "测试计划任务通知:" + user.getName() + "创建的" + "'" + testPlan.getName() + "'" + "计划开始时间是:" + "'" + start + "'" + ";" + "计划结束时间是:" + "'" + end + "'" + " " + "已删除"; - } - return context; - } - public TestCaseReportMetricDTO getStatisticsMetric(String planId) { QueryTestPlanRequest queryTestPlanRequest = new QueryTestPlanRequest(); queryTestPlanRequest.setId(planId); @@ -2134,8 +2065,10 @@ public class TestPlanService { Map executeQueue = new LinkedHashMap<>(); List responseDTOS = new LinkedList<>(); Map planScheduleReportInfoDTOMap = new LinkedHashMap<>(); + boolean startThread = true; for (TestPlanWithBLOBs testPlan : planList) { if(StringUtils.isBlank(testPlan.getRunModeConfig())){ + startThread = false; MSException.throwException("请保存["+testPlan.getName()+"]的运行配置"); } //创建测试报告,然后返回的ID重新赋值为resourceID,作为后续的参数 @@ -2157,7 +2090,7 @@ public class TestPlanService { extTestPlanExecutionQueueMapper.sqlInsert(planExecutionQueues); } // 开始选择执行模式 - runByMode(request, testPlanMap, planScheduleReportInfoDTOMap, planExecutionQueues); + runByMode(startThread,request, testPlanMap, planScheduleReportInfoDTOMap, planExecutionQueues); return responseDTOS; } @@ -2176,7 +2109,7 @@ public class TestPlanService { return planExecutionQueues; } - private void runByMode(TestplanRunRequest request, Map testPlanMap, Map planScheduleReportInfoDTOMap, List planExecutionQueues) { + private void runByMode(boolean startThread, TestplanRunRequest request, Map testPlanMap, Map planScheduleReportInfoDTOMap, List planExecutionQueues) { if (planExecutionQueues != null&& planExecutionQueues.size()>0) { Thread thread = new Thread(new Runnable() { @Override @@ -2200,7 +2133,9 @@ public class TestPlanService { } } }); - thread.start(); + if (startThread) { + thread.start(); + } } }