fix(测试计划): 修复单独执行测试计划组时无法正确对组内测试计划进行串行/并行执行的缺陷
This commit is contained in:
parent
e8a313e754
commit
29ca3d27c6
|
@ -168,9 +168,10 @@ public class TestPlanController {
|
||||||
@RequiresPermissions(PermissionConstants.TEST_PLAN_READ_ADD)
|
@RequiresPermissions(PermissionConstants.TEST_PLAN_READ_ADD)
|
||||||
@CheckOwner(resourceId = "#id", resourceType = "test_plan")
|
@CheckOwner(resourceId = "#id", resourceType = "test_plan")
|
||||||
public TestPlanOperationResponse copy(@PathVariable String id) {
|
public TestPlanOperationResponse copy(@PathVariable String id) {
|
||||||
return new TestPlanOperationResponse(
|
long copyCount = testPlanService.copy(id, SessionUtils.getUserId());
|
||||||
testPlanService.copy(id, SessionUtils.getUserId())
|
//copy完成之后的刷新一下状态
|
||||||
);
|
testPlanService.refreshTestPlanStatus(id);
|
||||||
|
return new TestPlanOperationResponse(copyCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/batch-copy")
|
@PostMapping("/batch-copy")
|
||||||
|
|
|
@ -29,7 +29,6 @@ import org.springframework.transaction.annotation.Transactional;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
import static io.metersphere.plan.service.TestPlanExecuteSupportService.*;
|
import static io.metersphere.plan.service.TestPlanExecuteSupportService.*;
|
||||||
|
|
||||||
|
@ -138,37 +137,27 @@ public class TestPlanExecuteService {
|
||||||
*/
|
*/
|
||||||
@Transactional(rollbackFor = Exception.class, propagation = Propagation.NOT_SUPPORTED)
|
@Transactional(rollbackFor = Exception.class, propagation = Propagation.NOT_SUPPORTED)
|
||||||
public String singleExecuteTestPlan(TestPlanExecuteRequest request, String userId) {
|
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(
|
TestPlanExecutionQueue singleExecuteRootQueue = new TestPlanExecutionQueue(
|
||||||
0,
|
0,
|
||||||
userId,
|
userId,
|
||||||
System.currentTimeMillis(),
|
System.currentTimeMillis(),
|
||||||
executionQueue.getQueueId(),
|
queueId,
|
||||||
QUEUE_PREFIX_TEST_PLAN_BATCH_EXECUTE,
|
QUEUE_PREFIX_TEST_PLAN_BATCH_EXECUTE,
|
||||||
executionQueue.getQueueId(),
|
null,
|
||||||
executionQueue.getQueueType(),
|
null,
|
||||||
request.getExecuteId(),
|
request.getExecuteId(),
|
||||||
executionQueue.getRunMode(),
|
request.getRunMode(),
|
||||||
executionQueue.getExecutionSource(),
|
request.getExecutionSource(),
|
||||||
IDGenerator.nextStr()
|
IDGenerator.nextStr()
|
||||||
);
|
);
|
||||||
|
|
||||||
String redisKey = testPlanExecuteSupportService.genQueueKey(executionQueue.getQueueId(), QUEUE_PREFIX_TEST_PLAN_BATCH_EXECUTE);
|
testPlanExecuteSupportService.setRedisForList(
|
||||||
redisTemplate.opsForList().rightPush(redisKey, JSON.toJSONString(singleExecuteRootQueue));
|
testPlanExecuteSupportService.genQueueKey(queueId, QUEUE_PREFIX_TEST_PLAN_BATCH_EXECUTE), List.of(JSON.toJSONString(singleExecuteRootQueue)));
|
||||||
redisTemplate.expire(redisKey, 1, TimeUnit.DAYS);
|
TestPlanExecutionQueue nextQueue = testPlanExecuteSupportService.getNextQueue(queueId, QUEUE_PREFIX_TEST_PLAN_BATCH_EXECUTE);
|
||||||
|
|
||||||
LogUtils.info("测试计划(组)的单独执行start!计划报告[{}] , 资源ID[{}]", singleExecuteRootQueue.getPrepareReportId(), singleExecuteRootQueue.getSourceID());
|
LogUtils.info("测试计划(组)的单独执行start!计划报告[{}] , 资源ID[{}]", singleExecuteRootQueue.getPrepareReportId(), singleExecuteRootQueue.getSourceID());
|
||||||
|
return executeTestPlanOrGroup(nextQueue);
|
||||||
String returnId = executeTestPlanOrGroup(executionQueue);
|
|
||||||
return returnId;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -235,7 +224,6 @@ public class TestPlanExecuteService {
|
||||||
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.setExecuteConfig(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());
|
||||||
|
@ -264,6 +252,7 @@ public class TestPlanExecuteService {
|
||||||
|
|
||||||
LogUtils.info("计划组的执行节点 --- 队列ID[{}],队列类型[{}],父队列ID[{}],父队列类型[{}]", queueId, queueType, executionQueue.getParentQueueId(), executionQueue.getParentQueueType());
|
LogUtils.info("计划组的执行节点 --- 队列ID[{}],队列类型[{}],父队列ID[{}],父队列类型[{}]", queueId, queueType, executionQueue.getParentQueueId(), executionQueue.getParentQueueType());
|
||||||
|
|
||||||
|
testPlanService.setExecuteConfig(executionQueue.getSourceID(), executionQueue.getPrepareReportId());
|
||||||
if (CollectionUtils.isEmpty(childrenQueue)) {
|
if (CollectionUtils.isEmpty(childrenQueue)) {
|
||||||
//本次的测试计划组执行完成
|
//本次的测试计划组执行完成
|
||||||
this.testPlanGroupQueueFinish(executionQueue.getQueueId(), executionQueue.getQueueType());
|
this.testPlanGroupQueueFinish(executionQueue.getQueueId(), executionQueue.getQueueType());
|
||||||
|
@ -273,14 +262,12 @@ public class TestPlanExecuteService {
|
||||||
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(), 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(), childQueue.getPrepareReportId());
|
||||||
testPlanService.setExecuteConfig(childQueue.getSourceID());
|
|
||||||
executeTestPlan(childQueue);
|
executeTestPlan(childQueue);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -290,8 +277,7 @@ 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()));
|
||||||
testPlanReportService.updateExecuteTimeAndStatus(executionQueue.getPrepareReportId());
|
testPlanService.setExecuteConfig(executionQueue.getSourceID(), executionQueue.getPrepareReportId());
|
||||||
testPlanService.setExecuteConfig(executionQueue.getSourceID());
|
|
||||||
this.executeTestPlan(executionQueue);
|
this.executeTestPlan(executionQueue);
|
||||||
return executionQueue.getPrepareReportId();
|
return executionQueue.getPrepareReportId();
|
||||||
}
|
}
|
||||||
|
@ -570,6 +556,8 @@ public class TestPlanExecuteService {
|
||||||
if (StringUtils.equalsIgnoreCase(queue.getQueueType(), QUEUE_PREFIX_TEST_PLAN_BATCH_EXECUTE)) {
|
if (StringUtils.equalsIgnoreCase(queue.getQueueType(), QUEUE_PREFIX_TEST_PLAN_BATCH_EXECUTE)) {
|
||||||
this.executeTestPlanOrGroup(queue);
|
this.executeTestPlanOrGroup(queue);
|
||||||
} else if (StringUtils.equalsIgnoreCase(queue.getQueueType(), QUEUE_PREFIX_TEST_PLAN_GROUP_EXECUTE)) {
|
} else if (StringUtils.equalsIgnoreCase(queue.getQueueType(), QUEUE_PREFIX_TEST_PLAN_GROUP_EXECUTE)) {
|
||||||
|
//执行下一个测试计划之前,将要修改的数据修改一下
|
||||||
|
testPlanService.setExecuteConfig(queue.getSourceID(), queue.getPrepareReportId());
|
||||||
this.executeTestPlan(queue);
|
this.executeTestPlan(queue);
|
||||||
} else if (StringUtils.equalsIgnoreCase(queue.getQueueType(), QUEUE_PREFIX_TEST_PLAN_CASE_TYPE)) {
|
} else if (StringUtils.equalsIgnoreCase(queue.getQueueType(), QUEUE_PREFIX_TEST_PLAN_CASE_TYPE)) {
|
||||||
this.executeByTestPlanCollection(queue);
|
this.executeByTestPlanCollection(queue);
|
||||||
|
|
|
@ -254,6 +254,10 @@ public class TestPlanReportService {
|
||||||
plans.forEach(plan -> {
|
plans.forEach(plan -> {
|
||||||
request.setTestPlanId(plan.getId());
|
request.setTestPlanId(plan.getId());
|
||||||
TestPlanReportGenPreParam genPreParam = buildReportGenParam(request, plan, prepareReportId);
|
TestPlanReportGenPreParam genPreParam = buildReportGenParam(request, plan, prepareReportId);
|
||||||
|
if (!manual) {
|
||||||
|
//不是手动保存的测试计划报告,不存储startTime
|
||||||
|
genPreParam.setStartTime(null);
|
||||||
|
}
|
||||||
genPreParam.setUseManual(manual);
|
genPreParam.setUseManual(manual);
|
||||||
//如果是测试计划的独立报告,使用参数中的预生成的报告id。否则只有测试计划组报告使用该id
|
//如果是测试计划的独立报告,使用参数中的预生成的报告id。否则只有测试计划组报告使用该id
|
||||||
String prepareItemReportId = isGroupReports ? IDGenerator.nextStr() : prepareReportId;
|
String prepareItemReportId = isGroupReports ? IDGenerator.nextStr() : prepareReportId;
|
||||||
|
@ -983,7 +987,6 @@ public class TestPlanReportService {
|
||||||
return extTestPlanReportMapper.getPlanReportListById(request);
|
return extTestPlanReportMapper.getPlanReportListById(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional(rollbackFor = Exception.class, propagation = Propagation.NOT_SUPPORTED)
|
|
||||||
public void updateExecuteTimeAndStatus(String prepareReportId) {
|
public void updateExecuteTimeAndStatus(String prepareReportId) {
|
||||||
extTestPlanReportMapper.batchUpdateExecuteTimeAndStatus(System.currentTimeMillis(), Collections.singletonList(prepareReportId));
|
extTestPlanReportMapper.batchUpdateExecuteTimeAndStatus(System.currentTimeMillis(), Collections.singletonList(prepareReportId));
|
||||||
}
|
}
|
||||||
|
|
|
@ -103,6 +103,8 @@ public class TestPlanService extends TestPlanBaseUtilsService {
|
||||||
|
|
||||||
private static final int MAX_TAG_SIZE = 10;
|
private static final int MAX_TAG_SIZE = 10;
|
||||||
private static final int MAX_CHILDREN_COUNT = 20;
|
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)
|
@Transactional(rollbackFor = Exception.class, propagation = Propagation.NOT_SUPPORTED)
|
||||||
public void setExecuteConfig(String sourceID) {
|
public void setExecuteConfig(String testPlanId, String testPlanReportId) {
|
||||||
this.setActualStartTime(sourceID);
|
this.setActualStartTime(testPlanId);
|
||||||
this.setTestPlanUnderway(sourceID);
|
this.setTestPlanUnderway(testPlanId);
|
||||||
|
if (StringUtils.isNotBlank(testPlanReportId)) {
|
||||||
|
testPlanReportService.updateExecuteTimeAndStatus(testPlanReportId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue