refactor(测试计划): 测试计划执行队列增加日志输出

This commit is contained in:
Jianguo-Genius 2024-06-17 17:23:24 +08:00 committed by Craftsman
parent 6abd36a18b
commit 849bff9498
3 changed files with 61 additions and 7 deletions

View File

@ -21,11 +21,13 @@ public class TestPlanScheduleJob extends BaseScheduleJob {
assert testPlanExecuteService != null; assert testPlanExecuteService != null;
Map<String, String> runConfig = JSON.parseObject(context.getJobDetail().getJobDataMap().get("config").toString(), Map.class); Map<String, String> runConfig = JSON.parseObject(context.getJobDetail().getJobDataMap().get("config").toString(), Map.class);
String runMode = runConfig.containsKey("runMode") ? runConfig.get("runMode") : ApiBatchRunMode.SERIAL.name(); String runMode = runConfig.containsKey("runMode") ? runConfig.get("runMode") : ApiBatchRunMode.SERIAL.name();
testPlanExecuteService.singleExecuteTestPlan(new TestPlanExecuteRequest() {{ Thread.startVirtualThread(() -> {
this.setExecuteId(resourceId); testPlanExecuteService.singleExecuteTestPlan(new TestPlanExecuteRequest() {{
this.setRunMode(runMode); this.setExecuteId(resourceId);
this.setExecutionSource(ApiExecuteRunMode.SCHEDULE.name()); this.setRunMode(runMode);
}}, userId); this.setExecutionSource(ApiExecuteRunMode.SCHEDULE.name());
}}, userId);
});
} }

View File

@ -146,6 +146,27 @@ public class TestPlanExecuteService {
executionQueue.setQueueType(QUEUE_PREFIX_TEST_PLAN_BATCH_EXECUTE); executionQueue.setQueueType(QUEUE_PREFIX_TEST_PLAN_BATCH_EXECUTE);
executionQueue.setCreateUser(userId); executionQueue.setCreateUser(userId);
executionQueue.setPrepareReportId(IDGenerator.nextStr()); executionQueue.setPrepareReportId(IDGenerator.nextStr());
TestPlanExecutionQueue singleExecuteRootQueue = new TestPlanExecutionQueue(
0,
userId,
System.currentTimeMillis(),
executionQueue.getQueueId(),
QUEUE_PREFIX_TEST_PLAN_BATCH_EXECUTE,
null,
null,
request.getExecuteId(),
request.getRunMode(),
executionQueue.getExecutionSource(),
IDGenerator.nextStr()
);
String redisKey = genQueueKey(executionQueue.getQueueId(), QUEUE_PREFIX_TEST_PLAN_BATCH_EXECUTE);
redisTemplate.opsForList().rightPush(genQueueKey(executionQueue.getQueueId(), QUEUE_PREFIX_TEST_PLAN_BATCH_EXECUTE), JSON.toJSONString(singleExecuteRootQueue));
redisTemplate.expire(genQueueKey(executionQueue.getQueueId(), QUEUE_PREFIX_TEST_PLAN_BATCH_EXECUTE), 1, TimeUnit.DAYS);
LogUtils.info("测试计划的单独执行start计划报告[{}] , 资源ID[{}]", singleExecuteRootQueue.getPrepareReportId(), singleExecuteRootQueue.getSourceID());
return executeTestPlanOrGroup(executionQueue); return executeTestPlanOrGroup(executionQueue);
} }
@ -163,6 +184,7 @@ public class TestPlanExecuteService {
//批量执行测试计划组 //批量执行测试计划组
public void batchExecuteTestPlan(TestPlanBatchExecuteRequest request, String userId) { public void batchExecuteTestPlan(TestPlanBatchExecuteRequest request, String userId) {
List<String> rightfulIds = testPlanService.selectRightfulIds(request.getExecuteIds()); List<String> rightfulIds = testPlanService.selectRightfulIds(request.getExecuteIds());
if (CollectionUtils.isNotEmpty(rightfulIds)) { if (CollectionUtils.isNotEmpty(rightfulIds)) {
String runMode = request.getRunMode(); String runMode = request.getRunMode();
String queueId = IDGenerator.nextStr(); String queueId = IDGenerator.nextStr();
@ -191,7 +213,7 @@ public class TestPlanExecuteService {
} }
} }
this.setRedisForList(genQueueKey(queueId, queueType), testPlanExecutionQueues.stream().map(JSON::toJSONString).toList()); this.setRedisForList(genQueueKey(queueId, queueType), testPlanExecutionQueues.stream().map(JSON::toJSONString).toList());
LogUtils.info("测试计划的批量执行start队列ID[{}] ,队列类型[{}] , 资源ID[{}]", queueId, queueType, JSON.toJSONString(rightfulIds));
if (StringUtils.equalsIgnoreCase(request.getRunMode(), ApiBatchRunMode.SERIAL.name())) { if (StringUtils.equalsIgnoreCase(request.getRunMode(), ApiBatchRunMode.SERIAL.name())) {
//串行 //串行
TestPlanExecutionQueue nextQueue = this.getNextQueue(queueId, queueType); TestPlanExecutionQueue nextQueue = this.getNextQueue(queueId, queueType);
@ -246,6 +268,9 @@ public class TestPlanExecuteService {
) )
); );
} }
LogUtils.info("计划组的执行节点 --- 队列ID[{}],队列类型[{}],父队列ID[{}],父队列类型[{}]", queueId, queueType, executionQueue.getParentQueueId(), executionQueue.getParentQueueType());
if (CollectionUtils.isEmpty(childrenQueue)) { if (CollectionUtils.isEmpty(childrenQueue)) {
//本次的测试计划组执行完成 //本次的测试计划组执行完成
this.testPlanGroupQueueFinish(executionQueue.getQueueId(), executionQueue.getQueueType()); this.testPlanGroupQueueFinish(executionQueue.getQueueId(), executionQueue.getQueueType());
@ -313,7 +338,7 @@ public class TestPlanExecuteService {
executionQueue.getPrepareReportId()) executionQueue.getPrepareReportId())
); );
} }
LogUtils.info("测试计划执行节点 --- 队列ID[{}],队列类型[{}],父队列ID[{}],父队列类型[{}],执行模式[{}]", queueId, queueType, executionQueue.getParentQueueId(), executionQueue.getParentQueueType(), runMode);
if (CollectionUtils.isEmpty(childrenQueue)) { if (CollectionUtils.isEmpty(childrenQueue)) {
//本次的测试计划组执行完成 //本次的测试计划组执行完成
this.testPlanExecuteQueueFinish(executionQueue.getQueueId(), executionQueue.getQueueType()); this.testPlanExecuteQueueFinish(executionQueue.getQueueId(), executionQueue.getQueueType());
@ -364,6 +389,7 @@ public class TestPlanExecuteService {
}} }}
); );
} }
LogUtils.info("测试计划不同用例类型的执行节点 --- 队列ID[{}],队列类型[{}],父队列ID[{}],父队列类型[{}],执行模式[{}]", queueId, queueType, executionQueue.getParentQueueId(), executionQueue.getParentQueueType(), executionQueue.getRunMode());
if (CollectionUtils.isEmpty(childrenQueue)) { if (CollectionUtils.isEmpty(childrenQueue)) {
//本次的测试集执行完成 //本次的测试集执行完成
this.caseTypeExecuteQueueFinish(executionQueue.getQueueId(), executionQueue.getQueueType()); this.caseTypeExecuteQueueFinish(executionQueue.getQueueId(), executionQueue.getQueueType());
@ -390,6 +416,7 @@ public class TestPlanExecuteService {
*/ */
private void executeCase(TestPlanExecutionQueue testPlanExecutionQueue) { private void executeCase(TestPlanExecutionQueue testPlanExecutionQueue) {
String queueId = testPlanExecutionQueue.getQueueId(); String queueId = testPlanExecutionQueue.getQueueId();
LogUtils.info("测试集执行节点 --- 队列ID[{}],队列类型[{}],父队列ID[{}],父队列类型[{}],执行模式[{}]", queueId, testPlanExecutionQueue.getQueueType(), testPlanExecutionQueue.getParentQueueId(), testPlanExecutionQueue.getParentQueueType(), testPlanExecutionQueue.getRunMode());
try { try {
boolean isFinish = false; boolean isFinish = false;
TestPlanCollection collection = JSON.parseObject(testPlanExecutionQueue.getTestPlanCollectionJson(), TestPlanCollection.class); TestPlanCollection collection = JSON.parseObject(testPlanExecutionQueue.getTestPlanCollectionJson(), TestPlanCollection.class);
@ -421,20 +448,24 @@ public class TestPlanExecuteService {
//测试集执行完成 //测试集执行完成
public void collectionExecuteQueueFinish(String queueID) { public void collectionExecuteQueueFinish(String queueID) {
String queueType = QUEUE_PREFIX_TEST_PLAN_COLLECTION; String queueType = QUEUE_PREFIX_TEST_PLAN_COLLECTION;
LogUtils.info("收到测试集执行完成的信息: 队列ID[{}],队列类型[{}],下一个节点的执行工作准备中...", queueID, queueType);
TestPlanExecutionQueue nextQueue = getNextQueue(queueID, queueType); TestPlanExecutionQueue nextQueue = getNextQueue(queueID, queueType);
if (StringUtils.equalsIgnoreCase(nextQueue.getRunMode(), ApiBatchRunMode.SERIAL.name())) { if (StringUtils.equalsIgnoreCase(nextQueue.getRunMode(), ApiBatchRunMode.SERIAL.name())) {
//串行时由于是先拿出节点再判断执行所以要判断节点的isExecuteFinish //串行时由于是先拿出节点再判断执行所以要判断节点的isExecuteFinish
if (!nextQueue.isExecuteFinish()) { if (!nextQueue.isExecuteFinish()) {
try { try {
LogUtils.info("测试集该节点的串行执行完成! --- 队列ID[{}],队列类型[{}]开始执行下一个队列ID[{}],类型[{}]", queueID, queueType, nextQueue.getQueueId(), nextQueue.getQueueType());
this.executeNextNode(nextQueue); this.executeNextNode(nextQueue);
} catch (Exception e) { } catch (Exception e) {
this.collectionExecuteQueueFinish(nextQueue.getQueueId()); this.collectionExecuteQueueFinish(nextQueue.getQueueId());
} }
} else { } else {
//当前测试集执行完毕 //当前测试集执行完毕
LogUtils.info("测试集串行执行Finish --- 队列ID[{}],队列类型[{}],已经执行完毕!", queueID, queueType);
this.queueExecuteFinish(nextQueue); this.queueExecuteFinish(nextQueue);
} }
} else if (nextQueue.isLastOne()) { } else if (nextQueue.isLastOne()) {
LogUtils.info("测试集并行执行Finish --- 队列ID[{}],队列类型[{}],已经执行完毕!", queueID, queueType);
//并行时调用回调时意味着执行结束所以判断是否是当前队列最后一个从而结束队列 //并行时调用回调时意味着执行结束所以判断是否是当前队列最后一个从而结束队列
this.queueExecuteFinish(nextQueue); this.queueExecuteFinish(nextQueue);
} }
@ -442,46 +473,55 @@ public class TestPlanExecuteService {
//测试计划中当前用例类型的全部执行完成 //测试计划中当前用例类型的全部执行完成
private void caseTypeExecuteQueueFinish(String queueID, String queueType) { private void caseTypeExecuteQueueFinish(String queueID, String queueType) {
LogUtils.info("收到用例类型执行队列的执行完成的信息: 队列ID[{}],队列类型[{}],下一个节点的执行工作准备中...", queueID, queueType);
TestPlanExecutionQueue nextQueue = getNextQueue(queueID, queueType); TestPlanExecutionQueue nextQueue = getNextQueue(queueID, queueType);
if (StringUtils.equalsIgnoreCase(nextQueue.getRunMode(), ApiBatchRunMode.SERIAL.name())) { if (StringUtils.equalsIgnoreCase(nextQueue.getRunMode(), ApiBatchRunMode.SERIAL.name())) {
//串行时由于是先拿出节点再判断执行所以要判断节点的isExecuteFinish //串行时由于是先拿出节点再判断执行所以要判断节点的isExecuteFinish
if (!nextQueue.isExecuteFinish()) { if (!nextQueue.isExecuteFinish()) {
try { try {
LogUtils.info("用例类型该节点的串行执行完成! --- 队列ID[{}],队列类型[{}]开始执行下一个队列ID[{}],类型[{}]", queueID, queueType, nextQueue.getQueueId(), nextQueue.getQueueType());
this.executeNextNode(nextQueue); this.executeNextNode(nextQueue);
} catch (Exception e) { } catch (Exception e) {
this.caseTypeExecuteQueueFinish(nextQueue.getQueueId(), nextQueue.getQueueType()); this.caseTypeExecuteQueueFinish(nextQueue.getQueueId(), nextQueue.getQueueType());
} }
} else { } else {
//当前测试计划执行完毕 //当前测试计划执行完毕
LogUtils.info("用例类型执行队列串行执行Finish --- 队列ID[{}],队列类型[{}],已经执行完毕!", queueID, queueType);
this.queueExecuteFinish(nextQueue); this.queueExecuteFinish(nextQueue);
} }
} else if (nextQueue.isLastOne()) { } else if (nextQueue.isLastOne()) {
//并行时调用回调时意味着执行结束所以判断是否是当前队列最后一个从而结束队列 //并行时调用回调时意味着执行结束所以判断是否是当前队列最后一个从而结束队列
LogUtils.info("用例类型执行队列并行执行Finish --- 队列ID[{}],队列类型[{}],已经执行完毕!", queueID, queueType);
this.queueExecuteFinish(nextQueue); this.queueExecuteFinish(nextQueue);
} }
} }
//测试计划执行完成 //测试计划执行完成
private void testPlanExecuteQueueFinish(String queueID, String queueType) { private void testPlanExecuteQueueFinish(String queueID, String queueType) {
LogUtils.info("收到测试计划执行完成的信息: 队列ID[{}],队列类型[{}],下一个节点的执行工作准备中...", queueID, queueType);
TestPlanExecutionQueue nextQueue = getNextQueue(queueID, queueType); TestPlanExecutionQueue nextQueue = getNextQueue(queueID, queueType);
if (StringUtils.equalsIgnoreCase(nextQueue.getRunMode(), ApiBatchRunMode.SERIAL.name())) { if (StringUtils.equalsIgnoreCase(nextQueue.getRunMode(), ApiBatchRunMode.SERIAL.name())) {
if (!nextQueue.isExecuteFinish()) { if (!nextQueue.isExecuteFinish()) {
try { try {
LogUtils.info("测试计划该节点的串行执行完成! --- 队列ID[{}],队列类型[{}]开始执行下一个队列ID[{}],类型[{}]", queueID, queueType, nextQueue.getQueueId(), nextQueue.getQueueType());
this.executeNextNode(nextQueue); this.executeNextNode(nextQueue);
} catch (Exception e) { } catch (Exception e) {
this.testPlanExecuteQueueFinish(nextQueue.getQueueId(), nextQueue.getQueueType()); this.testPlanExecuteQueueFinish(nextQueue.getQueueId(), nextQueue.getQueueType());
} }
} else { } else {
LogUtils.info("测试计划串行执行Finish --- 队列ID[{}],队列类型[{}],已经执行完毕!", queueID, queueType);
this.queueExecuteFinish(nextQueue); this.queueExecuteFinish(nextQueue);
} }
} else if (nextQueue.isLastOne()) { } else if (nextQueue.isLastOne()) {
//并行时调用回调时意味着执行结束所以判断是否是当前队列最后一个从而结束队列 //并行时调用回调时意味着执行结束所以判断是否是当前队列最后一个从而结束队列
LogUtils.info("测试计划并行执行Finish --- 队列ID[{}],队列类型[{}],已经执行完毕!", queueID, queueType);
this.queueExecuteFinish(nextQueue); this.queueExecuteFinish(nextQueue);
} }
} }
//测试计划批量执行队列节点执行完成 //测试计划批量执行队列节点执行完成
private void testPlanGroupQueueFinish(String queueID, String queueType) { private void testPlanGroupQueueFinish(String queueID, String queueType) {
LogUtils.info("收到计划组执行完成的信息: 队列ID[{}],队列类型[{}],下一个节点的执行工作准备中...", queueID, queueType);
TestPlanExecutionQueue nextQueue = getNextQueue(queueID, queueType); TestPlanExecutionQueue nextQueue = getNextQueue(queueID, queueType);
if (nextQueue == null) { if (nextQueue == null) {
return; return;
@ -489,12 +529,16 @@ public class TestPlanExecuteService {
if (StringUtils.equalsIgnoreCase(nextQueue.getRunMode(), ApiBatchRunMode.SERIAL.name())) { if (StringUtils.equalsIgnoreCase(nextQueue.getRunMode(), ApiBatchRunMode.SERIAL.name())) {
if (!nextQueue.isExecuteFinish()) { if (!nextQueue.isExecuteFinish()) {
try { try {
LogUtils.info("计划组该节点的串行执行完成! --- 队列ID[{}],队列类型[{}]开始执行下一个队列ID[{}],类型[{}]", queueID, queueType, nextQueue.getQueueId(), nextQueue.getQueueType());
this.executeNextNode(nextQueue); this.executeNextNode(nextQueue);
} catch (Exception e) { } catch (Exception e) {
this.testPlanGroupQueueFinish(queueID, queueType); this.testPlanGroupQueueFinish(queueID, queueType);
} }
} else {
LogUtils.info("计划组并行执行Finish --- 队列ID[{}],队列类型[{}],已经执行完毕!", queueID, queueType);
} }
} else { } else {
LogUtils.info("计划组并行执行Finish --- 队列ID[{}],队列类型[{}],已经执行完毕!", queueID, queueType);
//并行时调用回调时意味着执行结束所以判断是否是当前队列最后一个从而结束队列 //并行时调用回调时意味着执行结束所以判断是否是当前队列最后一个从而结束队列
this.queueExecuteFinish(nextQueue); this.queueExecuteFinish(nextQueue);
} }
@ -502,6 +546,7 @@ public class TestPlanExecuteService {
} }
private void executeNextNode(TestPlanExecutionQueue queue) { private void executeNextNode(TestPlanExecutionQueue queue) {
LogUtils.info("开始执行下一个节点: --- 队列ID[{}],队列类型[{}]预生成报告ID[{}]", queue.getQueueId(), queue.getQueueType(), queue.getPrepareReportId());
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)) {
@ -514,6 +559,7 @@ public class TestPlanExecuteService {
} }
private void summaryTestPlanReport(String reportId, boolean isGroupReport) { private void summaryTestPlanReport(String reportId, boolean isGroupReport) {
LogUtils.info("开始合并报告: --- 报告ID[{}],是否是报告组[{}]", reportId, isGroupReport);
try { try {
if (isGroupReport) { if (isGroupReport) {
testPlanReportService.summaryGroupReport(reportId); testPlanReportService.summaryGroupReport(reportId);
@ -540,6 +586,7 @@ public class TestPlanExecuteService {
} }
private void queueExecuteFinish(TestPlanExecutionQueue queue) { private void queueExecuteFinish(TestPlanExecutionQueue queue) {
LogUtils.info("当前节点执行完成: --- 队列ID[{}],队列类型[{}]父队列ID[{}],父队列类型[{}]", queue.getQueueId(), queue.getQueueType(), queue.getParentQueueId(), queue.getParentQueueType());
if (StringUtils.equalsIgnoreCase(queue.getParentQueueType(), QUEUE_PREFIX_TEST_PLAN_BATCH_EXECUTE)) { if (StringUtils.equalsIgnoreCase(queue.getParentQueueType(), QUEUE_PREFIX_TEST_PLAN_BATCH_EXECUTE)) {
if (StringUtils.equalsIgnoreCase(queue.getQueueType(), QUEUE_PREFIX_TEST_PLAN_GROUP_EXECUTE)) { if (StringUtils.equalsIgnoreCase(queue.getQueueType(), QUEUE_PREFIX_TEST_PLAN_GROUP_EXECUTE)) {
// 计划组报告汇总并统计 // 计划组报告汇总并统计

View File

@ -341,6 +341,11 @@ public class TestPlanService extends TestPlanBaseUtilsService {
//移动模块时重置GroupId //移动模块时重置GroupId
updateTestPlan.setGroupId(TestPlanConstants.TEST_PLAN_DEFAULT_GROUP_ID); updateTestPlan.setGroupId(TestPlanConstants.TEST_PLAN_DEFAULT_GROUP_ID);
} }
if (StringUtils.isNotBlank(request.getGroupId()) && !StringUtils.equalsIgnoreCase(request.getGroupId(), TestPlanConstants.TEST_PLAN_DEFAULT_GROUP_ID)) {
//移动测试计划到测试计划组中删除定时任务
updateTestPlan.setGroupId(request.getGroupId());
this.deleteScheduleConfig(request.getId());
}
if (StringUtils.isNotBlank(request.getName())) { if (StringUtils.isNotBlank(request.getName())) {
updateTestPlan.setName(request.getName()); updateTestPlan.setName(request.getName());
updateTestPlan.setProjectId(testPlan.getProjectId()); updateTestPlan.setProjectId(testPlan.getProjectId());