refactor(测试计划): 停止测试计划

This commit is contained in:
wxg0103 2024-06-15 20:30:47 +08:00 committed by Craftsman
parent 6f30f3476e
commit ffc3bfc934
2 changed files with 57 additions and 44 deletions

View File

@ -1,8 +1,8 @@
package io.metersphere.plan.service;
import com.esotericsoftware.minlog.Log;
import io.metersphere.plan.dto.TestPlanReportPostParam;
import io.metersphere.plan.domain.*;
import io.metersphere.plan.dto.TestPlanReportPostParam;
import io.metersphere.plan.dto.request.TestPlanBatchExecuteRequest;
import io.metersphere.plan.dto.request.TestPlanExecuteRequest;
import io.metersphere.plan.dto.request.TestPlanReportGenRequest;
@ -88,7 +88,7 @@ public class TestPlanExecuteService {
// 获取下一个要执行的测试计划节点目的是得到最后一条的queueId
TestPlanExecutionQueue nextTestPlanQueue = this.getNextQueue(testPlanReportId, QUEUE_PREFIX_TEST_PLAN_GROUP_EXECUTE);
if (nextTestPlanQueue == null || !StringUtils.equalsIgnoreCase(nextTestPlanQueue.getParentQueueType(), QUEUE_PREFIX_TEST_PLAN_BATCH_EXECUTE)) {
throw new MSException("停止执行测试计划组失败!无法获取到执行队列!");
return;
}
String groupExecuteQueueId = genQueueKey(testPlanReportId, QUEUE_PREFIX_TEST_PLAN_GROUP_EXECUTE);
@ -113,7 +113,7 @@ public class TestPlanExecuteService {
*/
TestPlanExecutionQueue nextTestPlanQueue = this.getNextQueue(testPlanReportId, QUEUE_PREFIX_TEST_PLAN_CASE_TYPE);
if (nextTestPlanQueue == null || !StringUtils.equalsAnyIgnoreCase(nextTestPlanQueue.getParentQueueType(), QUEUE_PREFIX_TEST_PLAN_GROUP_EXECUTE, QUEUE_PREFIX_TEST_PLAN_BATCH_EXECUTE)) {
throw new MSException("停止测试计划执行失败!无法获取到执行队列!");
return;
}
this.deepDeleteTestPlanCaseType(testPlanReport);
summaryTestPlanReport(testPlanReportId, false);
@ -159,6 +159,7 @@ public class TestPlanExecuteService {
redisTemplate.delete(redisKey);
redisTemplate.delete(genQueueKey(redisKey, LAST_QUEUE_PREFIX));
}
//批量执行测试计划组
public void batchExecuteTestPlan(TestPlanBatchExecuteRequest request, String userId) {
List<String> rightfulIds = testPlanService.selectRightfulIds(request.getExecuteIds());
@ -379,6 +380,7 @@ public class TestPlanExecuteService {
/**
* 批量执行单个测试集的用例
*
* @param testPlanExecutionQueue
*/
private void executeCase(TestPlanExecutionQueue testPlanExecutionQueue) {

View File

@ -82,10 +82,9 @@ public class TestPlanTaskCenterService {
ExtApiReportMapper extApiReportMapper;
@Resource
ExtApiScenarioReportMapper extApiScenarioReportMapper;
@Resource
TestPlanExecuteService testPlanExecuteService;
private static final String DEFAULT_SORT = "start_time desc";
private final static String PROJECT_STOP = "/task/center/api/project/stop";
private final static String ORG_STOP = "/task/center/api/org/stop";
private final static String SYSTEM_STOP = "/task/center/api/system/stop";
/**
* 任务中心实时任务列表-项目级
@ -275,12 +274,24 @@ public class TestPlanTaskCenterService {
}
//根据id去重
List<String> allReportIds = reports.stream().distinct().map(ReportDTO::getId).toList();
if (CollectionUtils.isNotEmpty(allReportIds)) {
// 查找和测试计划管理的接口用例的所有数据
List<ReportDTO> apiReports = extTestPlanReportMapper.getCaseReports(allReportIds);
//停止测试计划的队列
SubListUtils.dealForSubList(allReportIds, 10, (subList) -> {
subList.forEach(item -> {
try {
LogUtils.info(String.format("开始停止测试计划队列:%s", item));
testPlanExecuteService.stopTestPlanRunning(item);
} catch (Exception e) {
LogUtils.error("停止测试计划队列异常", e);
}
});
List<ReportDTO> apiReports = extTestPlanReportMapper.getCaseReports(subList);
detailReport(request, apiReports, userId, module, ApiExecuteResourceType.TEST_PLAN_API_CASE.name());
List<ReportDTO> scenarioReports = extTestPlanReportMapper.getScenarioReports(allReportIds);
List<ReportDTO> scenarioReports = extTestPlanReportMapper.getScenarioReports(subList);
detailReport(request, scenarioReports, userId, module, ApiExecuteResourceType.TEST_PLAN_API_SCENARIO.name());
});
}
}