fix(测试跟踪): 测试计划

--user=郭雨琦
解决批量执行测试计划时在提示配置未保存的时候,测试计划还在执行的问题
点击测试计划进入用例页面增加对计划结束时间的校验
删除了一个没有调用的方法
This commit is contained in:
guoyuqi 2022-04-12 17:35:10 +08:00 committed by xiaomeinvG
parent 5a12649d1a
commit a793d72e4e
1 changed files with 11 additions and 76 deletions

View File

@ -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<String> 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<String, TestPlanReport> executeQueue = new LinkedHashMap<>();
List<MsExecResponseDTO> responseDTOS = new LinkedList<>();
Map<String, TestPlanScheduleReportInfoDTO> 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<String, TestPlanWithBLOBs> testPlanMap, Map<String, TestPlanScheduleReportInfoDTO> planScheduleReportInfoDTOMap, List<TestPlanExecutionQueue> planExecutionQueues) {
private void runByMode(boolean startThread, TestplanRunRequest request, Map<String, TestPlanWithBLOBs> testPlanMap, Map<String, TestPlanScheduleReportInfoDTO> planScheduleReportInfoDTOMap, List<TestPlanExecutionQueue> 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();
}
}
}