fix(测试计划): 修复单独执行测试计划组时无法正确对组内测试计划进行串行/并行执行的缺陷

This commit is contained in:
Jianguo-Genius 2024-06-20 12:16:05 +08:00 committed by Craftsman
parent e8a313e754
commit 29ca3d27c6
4 changed files with 32 additions and 35 deletions

View File

@ -168,9 +168,10 @@ public class TestPlanController {
@RequiresPermissions(PermissionConstants.TEST_PLAN_READ_ADD)
@CheckOwner(resourceId = "#id", resourceType = "test_plan")
public TestPlanOperationResponse copy(@PathVariable String id) {
return new TestPlanOperationResponse(
testPlanService.copy(id, SessionUtils.getUserId())
);
long copyCount = testPlanService.copy(id, SessionUtils.getUserId());
//copy完成之后的刷新一下状态
testPlanService.refreshTestPlanStatus(id);
return new TestPlanOperationResponse(copyCount);
}
@PostMapping("/batch-copy")

View File

@ -29,7 +29,6 @@ import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import static io.metersphere.plan.service.TestPlanExecuteSupportService.*;
@ -138,37 +137,27 @@ public class TestPlanExecuteService {
*/
@Transactional(rollbackFor = Exception.class, propagation = Propagation.NOT_SUPPORTED)
public String singleExecuteTestPlan(TestPlanExecuteRequest request, String userId) {
TestPlanExecutionQueue executionQueue = new TestPlanExecutionQueue();
executionQueue.setSourceID(request.getExecuteId());
executionQueue.setRunMode(ApiBatchRunMode.PARALLEL.name());
executionQueue.setExecutionSource(request.getExecutionSource());
executionQueue.setQueueId(IDGenerator.nextStr());
executionQueue.setQueueType(QUEUE_PREFIX_TEST_PLAN_BATCH_EXECUTE);
executionQueue.setCreateUser(userId);
executionQueue.setPrepareReportId(IDGenerator.nextStr());
String queueId = IDGenerator.nextStr();
TestPlanExecutionQueue singleExecuteRootQueue = new TestPlanExecutionQueue(
0,
userId,
System.currentTimeMillis(),
executionQueue.getQueueId(),
queueId,
QUEUE_PREFIX_TEST_PLAN_BATCH_EXECUTE,
executionQueue.getQueueId(),
executionQueue.getQueueType(),
null,
null,
request.getExecuteId(),
executionQueue.getRunMode(),
executionQueue.getExecutionSource(),
request.getRunMode(),
request.getExecutionSource(),
IDGenerator.nextStr()
);
String redisKey = testPlanExecuteSupportService.genQueueKey(executionQueue.getQueueId(), QUEUE_PREFIX_TEST_PLAN_BATCH_EXECUTE);
redisTemplate.opsForList().rightPush(redisKey, JSON.toJSONString(singleExecuteRootQueue));
redisTemplate.expire(redisKey, 1, TimeUnit.DAYS);
testPlanExecuteSupportService.setRedisForList(
testPlanExecuteSupportService.genQueueKey(queueId, QUEUE_PREFIX_TEST_PLAN_BATCH_EXECUTE), List.of(JSON.toJSONString(singleExecuteRootQueue)));
TestPlanExecutionQueue nextQueue = testPlanExecuteSupportService.getNextQueue(queueId, QUEUE_PREFIX_TEST_PLAN_BATCH_EXECUTE);
LogUtils.info("测试计划的单独执行start计划报告[{}] , 资源ID[{}]", singleExecuteRootQueue.getPrepareReportId(), singleExecuteRootQueue.getSourceID());
String returnId = executeTestPlanOrGroup(executionQueue);
return returnId;
return executeTestPlanOrGroup(nextQueue);
}
/**
@ -235,7 +224,6 @@ public class TestPlanExecuteService {
genReportRequest.setProjectId(testPlan.getProjectId());
if (StringUtils.equalsIgnoreCase(testPlan.getType(), TestPlanConstants.TEST_PLAN_TYPE_GROUP)) {
//更改测试计划组的状态
testPlanService.setExecuteConfig(executionQueue.getSourceID());
List<TestPlan> children = testPlanService.selectNotArchivedChildren(testPlan.getId());
// 预生成计划组报告
Map<String, String> reportMap = testPlanReportService.genReportByExecution(executionQueue.getPrepareReportId(), genReportRequest, executionQueue.getCreateUser());
@ -264,6 +252,7 @@ public class TestPlanExecuteService {
LogUtils.info("计划组的执行节点 --- 队列ID[{}],队列类型[{}],父队列ID[{}],父队列类型[{}]", queueId, queueType, executionQueue.getParentQueueId(), executionQueue.getParentQueueType());
testPlanService.setExecuteConfig(executionQueue.getSourceID(), executionQueue.getPrepareReportId());
if (CollectionUtils.isEmpty(childrenQueue)) {
//本次的测试计划组执行完成
this.testPlanGroupQueueFinish(executionQueue.getQueueId(), executionQueue.getQueueType());
@ -273,14 +262,12 @@ public class TestPlanExecuteService {
if (StringUtils.equalsIgnoreCase(executionQueue.getRunMode(), ApiBatchRunMode.SERIAL.name())) {
//串行
TestPlanExecutionQueue nextQueue = testPlanExecuteSupportService.getNextQueue(queueId, queueType);
testPlanReportService.updateExecuteTimeAndStatus(nextQueue.getPrepareReportId());
testPlanService.setExecuteConfig(nextQueue.getSourceID());
testPlanService.setExecuteConfig(nextQueue.getSourceID(), nextQueue.getPrepareReportId());
executeTestPlan(nextQueue);
} else {
//并行
childrenQueue.forEach(childQueue -> {
testPlanReportService.updateExecuteTimeAndStatus(childQueue.getPrepareReportId());
testPlanService.setExecuteConfig(childQueue.getSourceID());
testPlanService.setExecuteConfig(childQueue.getSourceID(), childQueue.getPrepareReportId());
executeTestPlan(childQueue);
});
}
@ -290,8 +277,7 @@ public class TestPlanExecuteService {
} else {
Map<String, String> reportMap = testPlanReportService.genReportByExecution(executionQueue.getPrepareReportId(), genReportRequest, executionQueue.getCreateUser());
executionQueue.setPrepareReportId(reportMap.get(executionQueue.getSourceID()));
testPlanReportService.updateExecuteTimeAndStatus(executionQueue.getPrepareReportId());
testPlanService.setExecuteConfig(executionQueue.getSourceID());
testPlanService.setExecuteConfig(executionQueue.getSourceID(), executionQueue.getPrepareReportId());
this.executeTestPlan(executionQueue);
return executionQueue.getPrepareReportId();
}
@ -570,6 +556,8 @@ public class TestPlanExecuteService {
if (StringUtils.equalsIgnoreCase(queue.getQueueType(), QUEUE_PREFIX_TEST_PLAN_BATCH_EXECUTE)) {
this.executeTestPlanOrGroup(queue);
} else if (StringUtils.equalsIgnoreCase(queue.getQueueType(), QUEUE_PREFIX_TEST_PLAN_GROUP_EXECUTE)) {
//执行下一个测试计划之前将要修改的数据修改一下
testPlanService.setExecuteConfig(queue.getSourceID(), queue.getPrepareReportId());
this.executeTestPlan(queue);
} else if (StringUtils.equalsIgnoreCase(queue.getQueueType(), QUEUE_PREFIX_TEST_PLAN_CASE_TYPE)) {
this.executeByTestPlanCollection(queue);

View File

@ -254,6 +254,10 @@ public class TestPlanReportService {
plans.forEach(plan -> {
request.setTestPlanId(plan.getId());
TestPlanReportGenPreParam genPreParam = buildReportGenParam(request, plan, prepareReportId);
if (!manual) {
//不是手动保存的测试计划报告不存储startTime
genPreParam.setStartTime(null);
}
genPreParam.setUseManual(manual);
//如果是测试计划的独立报告使用参数中的预生成的报告id否则只有测试计划组报告使用该id
String prepareItemReportId = isGroupReports ? IDGenerator.nextStr() : prepareReportId;
@ -983,7 +987,6 @@ public class TestPlanReportService {
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

@ -103,6 +103,8 @@ public class TestPlanService extends TestPlanBaseUtilsService {
private static final int MAX_TAG_SIZE = 10;
private static final int MAX_CHILDREN_COUNT = 20;
@Autowired
private TestPlanReportService testPlanReportService;
/**
* 创建测试计划
@ -1060,8 +1062,11 @@ public class TestPlanService extends TestPlanBaseUtilsService {
}
@Transactional(rollbackFor = Exception.class, propagation = Propagation.NOT_SUPPORTED)
public void setExecuteConfig(String sourceID) {
this.setActualStartTime(sourceID);
this.setTestPlanUnderway(sourceID);
public void setExecuteConfig(String testPlanId, String testPlanReportId) {
this.setActualStartTime(testPlanId);
this.setTestPlanUnderway(testPlanId);
if (StringUtils.isNotBlank(testPlanReportId)) {
testPlanReportService.updateExecuteTimeAndStatus(testPlanReportId);
}
}
}