fix(测试计划): 修复测试计划查询模块id错误的问题

This commit is contained in:
Jianguo-Genius 2024-06-18 21:15:38 +08:00 committed by Craftsman
parent 93ace7f9fd
commit ebb42a6193
4 changed files with 37 additions and 22 deletions

View File

@ -5,7 +5,10 @@ import io.metersphere.plan.domain.*;
import io.metersphere.plan.dto.request.TestPlanBatchExecuteRequest; import io.metersphere.plan.dto.request.TestPlanBatchExecuteRequest;
import io.metersphere.plan.dto.request.TestPlanExecuteRequest; import io.metersphere.plan.dto.request.TestPlanExecuteRequest;
import io.metersphere.plan.dto.request.TestPlanReportGenRequest; import io.metersphere.plan.dto.request.TestPlanReportGenRequest;
import io.metersphere.plan.mapper.*; import io.metersphere.plan.mapper.TestPlanCollectionMapper;
import io.metersphere.plan.mapper.TestPlanConfigMapper;
import io.metersphere.plan.mapper.TestPlanMapper;
import io.metersphere.plan.mapper.TestPlanReportMapper;
import io.metersphere.sdk.constants.ApiBatchRunMode; import io.metersphere.sdk.constants.ApiBatchRunMode;
import io.metersphere.sdk.constants.CaseType; import io.metersphere.sdk.constants.CaseType;
import io.metersphere.sdk.constants.TaskTriggerMode; import io.metersphere.sdk.constants.TaskTriggerMode;
@ -17,10 +20,10 @@ import io.metersphere.sdk.util.LogUtils;
import io.metersphere.system.uid.IDGenerator; import io.metersphere.system.uid.IDGenerator;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList; import java.util.ArrayList;
@ -37,8 +40,6 @@ public class TestPlanExecuteService {
@Resource @Resource
private TestPlanMapper testPlanMapper; private TestPlanMapper testPlanMapper;
@Resource @Resource
private ExtTestPlanReportMapper extTestPlanReportMapper;
@Resource
private TestPlanConfigMapper testPlanConfigMapper; private TestPlanConfigMapper testPlanConfigMapper;
@Resource @Resource
private TestPlanService testPlanService; private TestPlanService testPlanService;
@ -226,9 +227,8 @@ public class TestPlanExecuteService {
genReportRequest.setTestPlanId(executionQueue.getSourceID()); genReportRequest.setTestPlanId(executionQueue.getSourceID());
genReportRequest.setProjectId(testPlan.getProjectId()); genReportRequest.setProjectId(testPlan.getProjectId());
if (StringUtils.equalsIgnoreCase(testPlan.getType(), TestPlanConstants.TEST_PLAN_TYPE_GROUP)) { if (StringUtils.equalsIgnoreCase(testPlan.getType(), TestPlanConstants.TEST_PLAN_TYPE_GROUP)) {
//更改测试计划组的状态
testPlanService.setActualStartTime(executionQueue.getSourceID()); testPlanService.setExecuteConfig(executionQueue.getSourceID());
testPlanService.setTestPlanUnderway(executionQueue.getSourceID());
List<TestPlan> children = testPlanService.selectNotArchivedChildren(testPlan.getId()); List<TestPlan> children = testPlanService.selectNotArchivedChildren(testPlan.getId());
// 预生成计划组报告 // 预生成计划组报告
Map<String, String> reportMap = testPlanReportService.genReportByExecution(executionQueue.getPrepareReportId(), genReportRequest, executionQueue.getCreateUser()); Map<String, String> reportMap = testPlanReportService.genReportByExecution(executionQueue.getPrepareReportId(), genReportRequest, executionQueue.getCreateUser());
@ -263,18 +263,17 @@ public class TestPlanExecuteService {
} else { } else {
testPlanExecuteSupportService.setRedisForList(testPlanExecuteSupportService.genQueueKey(queueId, queueType), childrenQueue.stream().map(JSON::toJSONString).toList()); testPlanExecuteSupportService.setRedisForList(testPlanExecuteSupportService.genQueueKey(queueId, queueType), childrenQueue.stream().map(JSON::toJSONString).toList());
// 更新报告的执行时间
if (MapUtils.isNotEmpty(reportMap)) {
extTestPlanReportMapper.batchUpdateExecuteTimeAndStatus(System.currentTimeMillis(), reportMap.values().stream().toList());
}
if (StringUtils.equalsIgnoreCase(executionQueue.getRunMode(), ApiBatchRunMode.SERIAL.name())) { if (StringUtils.equalsIgnoreCase(executionQueue.getRunMode(), ApiBatchRunMode.SERIAL.name())) {
//串行 //串行
TestPlanExecutionQueue nextQueue = testPlanExecuteSupportService.getNextQueue(queueId, queueType); TestPlanExecutionQueue nextQueue = testPlanExecuteSupportService.getNextQueue(queueId, queueType);
testPlanReportService.updateExecuteTimeAndStatus(nextQueue.getPrepareReportId());
testPlanService.setExecuteConfig(nextQueue.getSourceID());
executeTestPlan(nextQueue); executeTestPlan(nextQueue);
} else { } else {
//并行 //并行
childrenQueue.forEach(childQueue -> { childrenQueue.forEach(childQueue -> {
testPlanReportService.updateExecuteTimeAndStatus(childQueue.getPrepareReportId());
testPlanService.setExecuteConfig(childQueue.getSourceID());
executeTestPlan(childQueue); executeTestPlan(childQueue);
}); });
} }
@ -284,23 +283,21 @@ public class TestPlanExecuteService {
} else { } else {
Map<String, String> reportMap = testPlanReportService.genReportByExecution(executionQueue.getPrepareReportId(), genReportRequest, executionQueue.getCreateUser()); Map<String, String> reportMap = testPlanReportService.genReportByExecution(executionQueue.getPrepareReportId(), genReportRequest, executionQueue.getCreateUser());
executionQueue.setPrepareReportId(reportMap.get(executionQueue.getSourceID())); executionQueue.setPrepareReportId(reportMap.get(executionQueue.getSourceID()));
if (MapUtils.isNotEmpty(reportMap)) { testPlanReportService.updateExecuteTimeAndStatus(executionQueue.getPrepareReportId());
extTestPlanReportMapper.batchUpdateExecuteTimeAndStatus(System.currentTimeMillis(), reportMap.values().stream().toList()); testPlanService.setExecuteConfig(executionQueue.getSourceID());
}
this.executeTestPlan(executionQueue); this.executeTestPlan(executionQueue);
return executionQueue.getPrepareReportId(); return executionQueue.getPrepareReportId();
} }
} }
//执行测试计划里不同类型的用例 回调caseTypeExecuteQueueFinish //执行测试计划里不同类型的用例 回调caseTypeExecuteQueueFinish
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public void executeTestPlan(TestPlanExecutionQueue executionQueue) { public void executeTestPlan(TestPlanExecutionQueue executionQueue) {
boolean testPlanStopped = testPlanExecuteSupportService.checkTestPlanStopped(executionQueue.getPrepareReportId()); boolean testPlanStopped = testPlanExecuteSupportService.checkTestPlanStopped(executionQueue.getPrepareReportId());
if (testPlanStopped) { if (testPlanStopped) {
//测试计划报告状态已停止的话便不再执行执行下一个队列 //测试计划报告状态已停止的话便不再执行执行下一个队列
this.testPlanExecuteQueueFinish(executionQueue.getQueueId(), executionQueue.getQueueType()); this.testPlanExecuteQueueFinish(executionQueue.getQueueId(), executionQueue.getQueueType());
} else { } else {
testPlanService.setActualStartTime(executionQueue.getSourceID());
testPlanService.setTestPlanUnderway(executionQueue.getSourceID());
TestPlan testPlan = testPlanMapper.selectByPrimaryKey(executionQueue.getSourceID()); TestPlan testPlan = testPlanMapper.selectByPrimaryKey(executionQueue.getSourceID());
TestPlanCollectionExample testPlanCollectionExample = new TestPlanCollectionExample(); TestPlanCollectionExample testPlanCollectionExample = new TestPlanCollectionExample();
testPlanCollectionExample.createCriteria().andTestPlanIdEqualTo(testPlan.getId()).andParentIdEqualTo("NONE"); testPlanCollectionExample.createCriteria().andTestPlanIdEqualTo(testPlan.getId()).andParentIdEqualTo("NONE");
@ -473,6 +470,7 @@ public class TestPlanExecuteService {
//并行时调用回调时意味着执行结束所以判断是否是当前队列最后一个从而结束队列 //并行时调用回调时意味着执行结束所以判断是否是当前队列最后一个从而结束队列
this.queueExecuteFinish(nextQueue); this.queueExecuteFinish(nextQueue);
} }
} }
//测试计划中当前用例类型的全部执行完成 //测试计划中当前用例类型的全部执行完成
@ -558,7 +556,6 @@ public class TestPlanExecuteService {
//并行时调用回调时意味着执行结束所以判断是否是当前队列最后一个从而结束队列 //并行时调用回调时意味着执行结束所以判断是否是当前队列最后一个从而结束队列
this.queueExecuteFinish(nextQueue); this.queueExecuteFinish(nextQueue);
} }
} }
private void executeNextNode(TestPlanExecutionQueue queue) { private void executeNextNode(TestPlanExecutionQueue queue) {

View File

@ -15,6 +15,7 @@ import org.apache.commons.lang3.StringUtils;
import org.springframework.data.redis.core.ListOperations; import org.springframework.data.redis.core.ListOperations;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.List; import java.util.List;
@ -56,7 +57,7 @@ public class TestPlanExecuteSupportService {
redisTemplate.delete(genQueueKey(redisKey, LAST_QUEUE_PREFIX)); redisTemplate.delete(genQueueKey(redisKey, LAST_QUEUE_PREFIX));
} }
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public void summaryTestPlanReport(String reportId, boolean isGroupReport, boolean isStop) { public void summaryTestPlanReport(String reportId, boolean isGroupReport, boolean isStop) {
LogUtils.info("开始合并报告: --- 报告ID[{}],是否是报告组[{}]", reportId, isGroupReport); LogUtils.info("开始合并报告: --- 报告ID[{}],是否是报告组[{}]", reportId, isGroupReport);
try { try {
@ -80,7 +81,12 @@ public class TestPlanExecuteSupportService {
} }
} }
} catch (Exception e) { } catch (Exception e) {
LogUtils.error("Cannot find test plan report for " + reportId, e); LogUtils.error("测试计划报告汇总失败!reportId:" + reportId, e);
TestPlanReport stopReport = testPlanReportService.selectById(reportId);
stopReport.setId(reportId);
stopReport.setExecStatus(ExecStatus.ERROR.name());
stopReport.setEndTime(System.currentTimeMillis());
testPlanReportMapper.updateByPrimaryKeySelective(stopReport);
} }
} }

View File

@ -982,4 +982,9 @@ public class TestPlanReportService {
public List<TestPlanReportDetailResponse> planReportList(TestPlanReportDetailPageRequest request) { public List<TestPlanReportDetailResponse> planReportList(TestPlanReportDetailPageRequest request) {
return extTestPlanReportMapper.getPlanReportListById(request); return extTestPlanReportMapper.getPlanReportListById(request);
} }
@Transactional(rollbackFor = Exception.class, propagation = Propagation.NOT_SUPPORTED)
public void updateExecuteTimeAndStatus(String prepareReportId) {
extTestPlanReportMapper.batchUpdateExecuteTimeAndStatus(System.currentTimeMillis(), Collections.singletonList(prepareReportId));
}
} }

View File

@ -47,6 +47,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.*; import java.util.*;
@ -480,8 +481,8 @@ public class TestPlanService extends TestPlanBaseUtilsService {
TestPlanDetailResponse response = new TestPlanDetailResponse(); TestPlanDetailResponse response = new TestPlanDetailResponse();
String moduleName = Translator.get("unplanned.plan"); String moduleName = Translator.get("unplanned.plan");
if (!ModuleConstants.DEFAULT_NODE_ID.equals(id)) { if (!ModuleConstants.DEFAULT_NODE_ID.equals(testPlan.getModuleId())) {
TestPlanModule module = testPlanModuleMapper.selectByPrimaryKey(id); TestPlanModule module = testPlanModuleMapper.selectByPrimaryKey(testPlan.getModuleId());
moduleName = module == null ? Translator.get("unplanned.plan") : module.getName(); moduleName = module == null ? Translator.get("unplanned.plan") : module.getName();
response.setModuleId(module == null ? ModuleConstants.DEFAULT_NODE_ID : module.getId()); response.setModuleId(module == null ? ModuleConstants.DEFAULT_NODE_ID : module.getId());
} }
@ -993,4 +994,10 @@ public class TestPlanService extends TestPlanBaseUtilsService {
// 删除测试集 // 删除测试集
testPlanCollectionMapper.deleteByExample(example); testPlanCollectionMapper.deleteByExample(example);
} }
@Transactional(rollbackFor = Exception.class, propagation = Propagation.NOT_SUPPORTED)
public void setExecuteConfig(String sourceID) {
this.setActualStartTime(sourceID);
this.setTestPlanUnderway(sourceID);
}
} }