fix(测试计划): 停止测试计划,任务没有停止
--bug=1042662 --user=陈建星 【任务中心】停止计划任务-查看独立报告详情-报告分析-执行完成率统计错误 https://www.tapd.cn/55049933/s/1535336
This commit is contained in:
parent
c269b2382a
commit
af3a64689c
|
@ -263,7 +263,7 @@ public class ApiTestCaseController {
|
|||
@Operation(summary = "用例调试")
|
||||
@RequiresPermissions(PermissionConstants.PROJECT_API_DEFINITION_CASE_EXECUTE)
|
||||
public TaskRequestDTO debug(@Validated @RequestBody ApiCaseRunRequest request) {
|
||||
return apiTestCaseService.debug(request);
|
||||
return apiTestCaseService.debug(request, SessionUtils.getUserId());
|
||||
}
|
||||
|
||||
@GetMapping("/run/{id}")
|
||||
|
|
|
@ -110,6 +110,9 @@ public class MessageListener {
|
|||
private void executeNextTask(ApiNoticeDTO dto) {
|
||||
try {
|
||||
ExecutionQueue queue = apiExecutionQueueService.getQueue(dto.getQueueId());
|
||||
if (queue == null) {
|
||||
return;
|
||||
}
|
||||
if (isStopOnFailure(dto)) {
|
||||
ApiExecuteResourceType resourceType = EnumValidator.validateEnum(ApiExecuteResourceType.class, queue.getResourceType());
|
||||
// 补充集成报告
|
||||
|
@ -118,7 +121,7 @@ public class MessageListener {
|
|||
apiExecutionQueueService.deleteQueue(queue.getQueueId());
|
||||
// 失败停止,删除父队列等
|
||||
ApiExecuteCallbackServiceInvoker.stopCollectionOnFailure(dto.getResourceType(), dto.getParentQueueId());
|
||||
} else if (queue != null) {
|
||||
} else {
|
||||
// queue 不为 null 说明有下个任务
|
||||
ExecutionQueueDetail nextDetail = apiExecutionQueueService.getNextDetail(dto.getQueueId());
|
||||
if (nextDetail != null) {
|
||||
|
|
|
@ -41,7 +41,21 @@ public class ApiBatchRunBaseService {
|
|||
* @return
|
||||
*/
|
||||
public ExecutionQueue initExecutionqueue(List<String> resourceIds, ApiRunModeConfigDTO runModeConfig, String resourceType, String parentQueueId, String userId) {
|
||||
return initExecutionqueue(null, resourceIds, runModeConfig, resourceType, parentQueueId, userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化执行队列
|
||||
*
|
||||
* @param resourceIds
|
||||
* @param runModeConfig
|
||||
* @return
|
||||
*/
|
||||
public ExecutionQueue initExecutionqueue(String queueId, List<String> resourceIds, ApiRunModeConfigDTO runModeConfig, String resourceType, String parentQueueId, String userId) {
|
||||
ExecutionQueue queue = getExecutionQueue(runModeConfig, resourceType, userId);
|
||||
if (StringUtils.isNotBlank(queueId)) {
|
||||
queue.setQueueId(queueId);
|
||||
}
|
||||
queue.setParentQueueId(parentQueueId);
|
||||
List<ExecutionQueueDetail> queueDetails = getExecutionQueueDetails(resourceIds);
|
||||
apiExecutionQueueService.insertQueue(queue, queueDetails);
|
||||
|
@ -55,10 +69,7 @@ public class ApiBatchRunBaseService {
|
|||
* @return
|
||||
*/
|
||||
public ExecutionQueue initExecutionqueue(List<String> resourceIds, String resourceType, String userId) {
|
||||
ExecutionQueue queue = getExecutionQueue(null, resourceType, userId);
|
||||
List<ExecutionQueueDetail> queueDetails = getExecutionQueueDetails(resourceIds);
|
||||
apiExecutionQueueService.insertQueue(queue, queueDetails);
|
||||
return queue;
|
||||
return initExecutionqueue(resourceIds, null, resourceType, null, userId);
|
||||
}
|
||||
|
||||
public List<ExecutionQueueDetail> getExecutionQueueDetails(List<String> resourceIds) {
|
||||
|
|
|
@ -717,6 +717,7 @@ public class ApiTestCaseService extends MoveNodeService {
|
|||
TaskInfo taskInfo = taskRequest.getTaskInfo();
|
||||
taskInfo.getRunModeConfig().setPoolId(poolId);
|
||||
taskInfo.setSaveResult(true);
|
||||
taskInfo.setUserId(userId);
|
||||
|
||||
if (StringUtils.isEmpty(taskItem.getReportId())) {
|
||||
taskInfo.setRealTime(false);
|
||||
|
@ -740,11 +741,12 @@ public class ApiTestCaseService extends MoveNodeService {
|
|||
* @param request
|
||||
* @return
|
||||
*/
|
||||
public TaskRequestDTO debug(ApiCaseRunRequest request) {
|
||||
public TaskRequestDTO debug(ApiCaseRunRequest request, String userId) {
|
||||
TaskRequestDTO taskRequest = getTaskRequest(request.getReportId(), request.getId(),
|
||||
request.getProjectId(), apiExecuteService.getDebugRunModule(request.getFrontendDebug()));
|
||||
taskRequest.getTaskInfo().setSaveResult(false);
|
||||
taskRequest.getTaskInfo().setRealTime(true);
|
||||
taskRequest.getTaskInfo().setUserId(userId);
|
||||
|
||||
ApiResourceRunRequest runRequest = apiExecuteService.getApiResourceRunRequest(request);
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ import io.metersphere.sdk.util.JSON;
|
|||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.data.redis.core.ListOperations;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
@ -22,16 +22,16 @@ public class ApiExecutionQueueService {
|
|||
public static final String QUEUE_DETAIL_PREFIX = "queue:detail:";
|
||||
|
||||
@Resource
|
||||
private RedisTemplate<String, String> redisTemplate;
|
||||
private StringRedisTemplate stringRedisTemplate;
|
||||
|
||||
@Transactional(propagation = Propagation.REQUIRES_NEW)
|
||||
public void insertQueue(ExecutionQueue queue, List<ExecutionQueueDetail> queues) {
|
||||
// 保存队列信息
|
||||
redisTemplate.opsForValue().setIfAbsent(QUEUE_PREFIX + queue.getQueueId(), JSON.toJSONString(queue), 1, TimeUnit.DAYS);
|
||||
stringRedisTemplate.opsForValue().setIfAbsent(QUEUE_PREFIX + queue.getQueueId(), JSON.toJSONString(queue), 1, TimeUnit.DAYS);
|
||||
// 保存队列详情信息
|
||||
List<String> queueStrItems = queues.stream().map(JSON::toJSONString).toList();
|
||||
redisTemplate.opsForList().rightPushAll(QUEUE_DETAIL_PREFIX + queue.getQueueId(), queueStrItems);
|
||||
redisTemplate.expire(QUEUE_DETAIL_PREFIX + queue.getQueueId(), 1, TimeUnit.DAYS);
|
||||
stringRedisTemplate.opsForList().rightPushAll(QUEUE_DETAIL_PREFIX + queue.getQueueId(), queueStrItems);
|
||||
stringRedisTemplate.expire(QUEUE_DETAIL_PREFIX + queue.getQueueId(), 1, TimeUnit.DAYS);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -39,12 +39,12 @@ public class ApiExecutionQueueService {
|
|||
*/
|
||||
public ExecutionQueueDetail getNextDetail(String queueId) {
|
||||
String queueKey = QUEUE_DETAIL_PREFIX + queueId;
|
||||
ListOperations<String, String> listOps = redisTemplate.opsForList();
|
||||
ListOperations<String, String> listOps = stringRedisTemplate.opsForList();
|
||||
String queueDetail = listOps.leftPop(queueKey);
|
||||
if (StringUtils.isBlank(queueDetail)) {
|
||||
// 重试3次获取
|
||||
for (int i = 0; i < 3; i++) {
|
||||
queueDetail = redisTemplate.opsForList().leftPop(queueKey);
|
||||
queueDetail = stringRedisTemplate.opsForList().leftPop(queueKey);
|
||||
if (StringUtils.isNotBlank(queueDetail)) {
|
||||
break;
|
||||
}
|
||||
|
@ -72,8 +72,8 @@ public class ApiExecutionQueueService {
|
|||
}
|
||||
|
||||
public void deleteQueue(String queueId) {
|
||||
redisTemplate.delete(QUEUE_DETAIL_PREFIX + queueId);
|
||||
redisTemplate.delete(QUEUE_PREFIX + queueId);
|
||||
stringRedisTemplate.delete(QUEUE_DETAIL_PREFIX + queueId);
|
||||
stringRedisTemplate.delete(QUEUE_PREFIX + queueId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -82,7 +82,7 @@ public class ApiExecutionQueueService {
|
|||
public List<ExecutionQueueDetail> getDetails(String queueId) {
|
||||
String queueKey = QUEUE_DETAIL_PREFIX + queueId;
|
||||
List<ExecutionQueueDetail> details = new LinkedList<>();
|
||||
ListOperations<String, String> listOps = redisTemplate.opsForList();
|
||||
ListOperations<String, String> listOps = stringRedisTemplate.opsForList();
|
||||
Long listSize = listOps.size(queueKey);
|
||||
if (listSize == null) {
|
||||
return details;
|
||||
|
@ -100,7 +100,7 @@ public class ApiExecutionQueueService {
|
|||
* 获取队列信息
|
||||
*/
|
||||
public ExecutionQueue getQueue(String queueId) {
|
||||
String queue = redisTemplate.opsForValue().get(QUEUE_PREFIX + queueId);
|
||||
String queue = stringRedisTemplate.opsForValue().get(QUEUE_PREFIX + queueId);
|
||||
if (StringUtils.isNotBlank(queue)) {
|
||||
return JSON.parseObject(queue, ExecutionQueue.class);
|
||||
}
|
||||
|
@ -108,7 +108,7 @@ public class ApiExecutionQueueService {
|
|||
}
|
||||
|
||||
public Long size(String queueId) {
|
||||
ListOperations<String, String> listOps = redisTemplate.opsForList();
|
||||
ListOperations<String, String> listOps = stringRedisTemplate.opsForList();
|
||||
|
||||
String queueKey = QUEUE_DETAIL_PREFIX + queueId;
|
||||
return listOps.size(queueKey);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package io.metersphere.api.service.queue;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -13,7 +13,7 @@ public class ApiExecutionSetService {
|
|||
public static final String SET_PREFIX = "set:";
|
||||
|
||||
@Resource
|
||||
private RedisTemplate<String, String> redisTemplate;
|
||||
private StringRedisTemplate stringRedisTemplate;
|
||||
|
||||
/**
|
||||
* 初始化执行集合
|
||||
|
@ -23,8 +23,8 @@ public class ApiExecutionSetService {
|
|||
*/
|
||||
public void initSet(String setId, List<String> resourceIds) {
|
||||
String key = getKey(setId);
|
||||
redisTemplate.opsForSet().add(key, resourceIds.toArray(new String[0]));
|
||||
redisTemplate.expire(key, 1, TimeUnit.DAYS);
|
||||
stringRedisTemplate.opsForSet().add(key, resourceIds.toArray(new String[0]));
|
||||
stringRedisTemplate.expire(key, 1, TimeUnit.DAYS);
|
||||
}
|
||||
|
||||
private String getKey(String setId) {
|
||||
|
@ -35,11 +35,11 @@ public class ApiExecutionSetService {
|
|||
* 从执行集合中去除选项
|
||||
*/
|
||||
public void removeItem(String setId, String resourceId) {
|
||||
redisTemplate.opsForSet().remove(SET_PREFIX + setId, resourceId);
|
||||
Long size = redisTemplate.opsForSet().size(SET_PREFIX + setId);
|
||||
stringRedisTemplate.opsForSet().remove(SET_PREFIX + setId, resourceId);
|
||||
Long size = stringRedisTemplate.opsForSet().size(SET_PREFIX + setId);
|
||||
if (size == null || size == 0) {
|
||||
// 集合没有元素,则删除集合
|
||||
redisTemplate.delete(SET_PREFIX + setId);
|
||||
stringRedisTemplate.delete(SET_PREFIX + setId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -93,7 +93,7 @@ public class ApiScenarioBatchRunService {
|
|||
*
|
||||
* @param request
|
||||
*/
|
||||
public void serialExecute(ApiScenarioBatchRunRequest request, String userId) throws Exception {
|
||||
public void serialExecute(ApiScenarioBatchRunRequest request, String userId) {
|
||||
List<String> ids = apiScenarioService.doSelectIds(request, false);
|
||||
ApiRunModeConfigDTO runModeConfig = getRunModeConfig(request);
|
||||
// 初始化集成报告
|
||||
|
@ -143,6 +143,7 @@ public class ApiScenarioBatchRunService {
|
|||
}).toList();
|
||||
TaskBatchRequestDTO taskRequest = getTaskBatchRequestDTO(request.getProjectId(), runModeConfig);
|
||||
taskRequest.setTaskItems(taskItems);
|
||||
taskRequest.getTaskInfo().setUserId(userId);
|
||||
|
||||
apiExecuteService.batchExecute(taskRequest);
|
||||
}
|
||||
|
@ -268,6 +269,7 @@ public class ApiScenarioBatchRunService {
|
|||
TaskItem taskItem = apiExecuteService.getTaskItem(reportId, queueDetail.getResourceId());
|
||||
taskRequest.setTaskItem(taskItem);
|
||||
taskRequest.getTaskInfo().setQueueId(queue.getQueueId());
|
||||
taskRequest.getTaskInfo().setUserId(queue.getUserId());
|
||||
|
||||
apiExecuteService.execute(taskRequest);
|
||||
}
|
||||
|
|
|
@ -191,6 +191,7 @@ public class ApiScenarioRunService {
|
|||
taskInfo.setSaveResult(true);
|
||||
taskInfo.getRunModeConfig().setEnvironmentId(parseParam.getEnvironmentId());
|
||||
taskRequest.getTaskItem().setRequestCount(tmpParam.getRequestCount().get());
|
||||
taskInfo.setUserId(userId);
|
||||
|
||||
if (StringUtils.isEmpty(taskItem.getReportId())) {
|
||||
taskInfo.setRealTime(false);
|
||||
|
|
|
@ -126,7 +126,7 @@ public class TestPlanApiCaseController {
|
|||
@GetMapping("/run/{id}")
|
||||
@Operation(summary = "用例执行")
|
||||
@RequiresPermissions(PermissionConstants.TEST_PLAN_READ_EXECUTE)
|
||||
// @CheckOwner(resourceId = "#id", resourceType = "test_plan_api_case") todo
|
||||
@CheckOwner(resourceId = "#id", resourceType = "test_plan_api_case", relationType = "test_plan")
|
||||
public TaskRequestDTO run(@PathVariable String id,
|
||||
@Schema(description = "报告ID,传了可以实时获取结果,不传则不支持实时获取")
|
||||
@RequestParam(required = false) String reportId) {
|
||||
|
@ -137,7 +137,7 @@ public class TestPlanApiCaseController {
|
|||
@PostMapping("/batch/run")
|
||||
@Operation(summary = "批量执行")
|
||||
@RequiresPermissions(PermissionConstants.TEST_PLAN_READ_EXECUTE)
|
||||
// @CheckOwner(resourceId = "#request.getId()", resourceType = "test_plan_api_case") todo
|
||||
@CheckOwner(resourceId = "#request.getId()", resourceType = "test_plan_api_case", relationType = "test_plan")
|
||||
public void batchRun(@Validated @RequestBody TestPlanApiCaseBatchRunRequest request) {
|
||||
testPlanApiCaseBatchRunService.asyncBatchRun(request, SessionUtils.getUserId());
|
||||
}
|
||||
|
|
|
@ -79,7 +79,7 @@ public class TestPlanApiScenarioController {
|
|||
@GetMapping("/run/{id}")
|
||||
@Operation(summary = "接口测试-接口场景管理-场景执行")
|
||||
@RequiresPermissions(PermissionConstants.TEST_PLAN_READ_EXECUTE)
|
||||
// @CheckOwner(resourceId = "#id", resourceType = "test_plan_api_scenario")
|
||||
@CheckOwner(resourceId = "#id", resourceType = "test_plan_api_scenario", relationType = "test_plan")
|
||||
public TaskRequestDTO run(@PathVariable String id, @RequestParam(required = false) String reportId) {
|
||||
return testPlanApiScenarioService.run(id, reportId, SessionUtils.getUserId());
|
||||
}
|
||||
|
@ -87,7 +87,7 @@ public class TestPlanApiScenarioController {
|
|||
@PostMapping("/batch/run")
|
||||
@Operation(summary = "批量执行")
|
||||
@RequiresPermissions(PermissionConstants.TEST_PLAN_READ_EXECUTE)
|
||||
// @CheckOwner(resourceId = "#request.getId()", resourceType = "test_plan_api_case") todo
|
||||
@CheckOwner(resourceId = "#request.getId()", resourceType = "test_plan_api_scenario", relationType = "test_plan")
|
||||
public void batchRun(@Validated @RequestBody TestPlanApiScenarioBatchRunRequest request) {
|
||||
testPlanApiScenarioBatchRunService.asyncBatchRun(request, SessionUtils.getUserId());
|
||||
}
|
||||
|
|
|
@ -443,7 +443,7 @@
|
|||
<select id="getIdsByReportIdAndCollectionId" resultType="java.lang.String">
|
||||
select id from test_plan_report_api_scenario
|
||||
where test_plan_report_id = #{testPlanReportId} and test_plan_collection_id = #{collectionId}
|
||||
order by pos
|
||||
order by pos desc
|
||||
</select>
|
||||
<sql id="queryWhereConditionByBatchQueryRequest">
|
||||
<if test="request.condition.keyword != null and request.condition.keyword != ''">
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
<select id="getIdsByReportIdAndCollectionId" resultType="java.lang.String">
|
||||
select id from test_plan_report_api_case
|
||||
where test_plan_report_id = #{testPlanReportId} and test_plan_collection_id = #{collectionId}
|
||||
order by pos
|
||||
order by pos desc
|
||||
</select>
|
||||
|
||||
<sql id="filter">
|
||||
|
|
|
@ -88,8 +88,9 @@ public class PlanRunTestPlanApiCaseService {
|
|||
return true;
|
||||
}
|
||||
|
||||
String queueId = testPlanExecutionQueue.getPrepareReportId() + "_" + collection.getId();
|
||||
// 先初始化集成报告,设置好报告ID,再初始化执行队列
|
||||
ExecutionQueue queue = apiBatchRunBaseService.initExecutionqueue(ids, runModeConfig, ApiExecuteResourceType.PLAN_RUN_API_CASE.name(), parentQueueId, userId);
|
||||
ExecutionQueue queue = apiBatchRunBaseService.initExecutionqueue(queueId, ids, runModeConfig, ApiExecuteResourceType.PLAN_RUN_API_CASE.name(), parentQueueId, userId);
|
||||
|
||||
// 执行第一个任务
|
||||
ExecutionQueueDetail nextDetail = apiExecutionQueueService.getNextDetail(queue.getQueueId());
|
||||
|
|
|
@ -83,8 +83,10 @@ public class PlanRunTestPlanApiScenarioService {
|
|||
return true;
|
||||
}
|
||||
|
||||
String queueId = testPlanExecutionQueue.getPrepareReportId() + "_" + collection.getId();
|
||||
|
||||
// 先初始化集成报告,设置好报告ID,再初始化执行队列
|
||||
ExecutionQueue queue = apiBatchRunBaseService.initExecutionqueue(ids, runModeConfig, ApiExecuteResourceType.PLAN_RUN_API_SCENARIO.name(), parentQueueId, userId);
|
||||
ExecutionQueue queue = apiBatchRunBaseService.initExecutionqueue(queueId, ids, runModeConfig, ApiExecuteResourceType.PLAN_RUN_API_SCENARIO.name(), parentQueueId, userId);
|
||||
// 执行第一个任务
|
||||
ExecutionQueueDetail nextDetail = apiExecutionQueueService.getNextDetail(queue.getQueueId());
|
||||
executeNextTask(queue, nextDetail);
|
||||
|
|
|
@ -297,6 +297,7 @@ public class TestPlanApiCaseBatchRunService {
|
|||
TaskRequestDTO taskRequest = getTaskRequestDTO(reportId, testPlanApiCase.getId(), apiTestCase, runModeConfig);
|
||||
taskRequest.getTaskInfo().setQueueId(queue.getQueueId());
|
||||
taskRequest.getTaskInfo().setParentQueueId(queue.getParentQueueId());
|
||||
taskRequest.getTaskInfo().setUserId(queue.getUserId());
|
||||
taskRequest.getTaskItem().setRequestCount(1L);
|
||||
|
||||
apiExecuteService.execute(taskRequest);
|
||||
|
|
|
@ -21,7 +21,6 @@ import io.metersphere.system.uid.IDGenerator;
|
|||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
@ -53,9 +52,6 @@ public class TestPlanExecuteService {
|
|||
@Resource
|
||||
private TestPlanApiBatchRunBaseService testPlanApiBatchRunBaseService;
|
||||
|
||||
@Resource
|
||||
private RedisTemplate<String, String> redisTemplate;
|
||||
|
||||
@Resource
|
||||
private TestPlanReportMapper testPlanReportMapper;
|
||||
@Resource
|
||||
|
@ -119,16 +115,9 @@ public class TestPlanExecuteService {
|
|||
}
|
||||
|
||||
private void deepDeleteTestPlanCaseType(TestPlanReport report) {
|
||||
testPlanExecuteSupportService.deleteRedisKey(
|
||||
testPlanExecuteSupportService.genQueueKey(report.getId(), QUEUE_PREFIX_TEST_PLAN_CASE_TYPE));
|
||||
TestPlanCollectionExample collectionExample = new TestPlanCollectionExample();
|
||||
collectionExample.createCriteria().andTestPlanIdEqualTo(report.getTestPlanId()).andParentIdEqualTo(TestPlanConstants.DEFAULT_PARENT_ID);
|
||||
List<TestPlanCollection> parentTestPlanCollectionList = testPlanCollectionMapper.selectByExample(collectionExample);
|
||||
parentTestPlanCollectionList.forEach(parentCollection -> {
|
||||
testPlanExecuteSupportService.deleteRedisKey(
|
||||
testPlanExecuteSupportService.genQueueKey(report.getId() + "_" + parentCollection.getId(), QUEUE_PREFIX_TEST_PLAN_COLLECTION));
|
||||
//todo @Chen-Jianxing 这里要同步清理用例/场景的执行队列
|
||||
});
|
||||
// 删除该任务相关的队列
|
||||
testPlanExecuteSupportService.keys("*" + report.getId() + "*")
|
||||
.forEach(key -> testPlanExecuteSupportService.deleteQueue(key));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -411,13 +400,13 @@ public class TestPlanExecuteService {
|
|||
TestPlanCollection extendedRootCollection = testPlanApiBatchRunBaseService.getExtendedRootCollection(collection);
|
||||
String executeMethod = extendedRootCollection == null ? collection.getExecuteMethod() : extendedRootCollection.getExecuteMethod();
|
||||
if (StringUtils.equalsIgnoreCase(collection.getType(), CaseType.API_CASE.getKey())) {
|
||||
if (StringUtils.equals(executeMethod, ApiBatchRunMode.PARALLEL.name())) {
|
||||
if (isParallel(executeMethod)) {
|
||||
execOver = planRunTestPlanApiCaseService.parallelExecute(testPlanExecutionQueue);
|
||||
} else {
|
||||
execOver = planRunTestPlanApiCaseService.serialExecute(testPlanExecutionQueue);
|
||||
}
|
||||
} else if (StringUtils.equalsIgnoreCase(collection.getType(), CaseType.SCENARIO_CASE.getKey())) {
|
||||
if (StringUtils.equals(executeMethod, ApiBatchRunMode.PARALLEL.name())) {
|
||||
if (isParallel(executeMethod)) {
|
||||
execOver = planRunTestPlanApiScenarioService.parallelExecute(testPlanExecutionQueue);
|
||||
} else {
|
||||
execOver = planRunTestPlanApiScenarioService.serialExecute(testPlanExecutionQueue);
|
||||
|
@ -434,6 +423,10 @@ public class TestPlanExecuteService {
|
|||
}
|
||||
}
|
||||
|
||||
private boolean isParallel(String executeMethod) {
|
||||
return StringUtils.equals(executeMethod, ApiBatchRunMode.PARALLEL.name());
|
||||
}
|
||||
|
||||
//测试集执行完成
|
||||
public void collectionExecuteQueueFinish(String queueID) {
|
||||
String queueType = QUEUE_PREFIX_TEST_PLAN_COLLECTION;
|
||||
|
|
|
@ -13,12 +13,13 @@ import io.metersphere.sdk.util.LogUtils;
|
|||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.data.redis.core.ListOperations;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Service
|
||||
|
@ -30,7 +31,7 @@ public class TestPlanExecuteSupportService {
|
|||
@Resource
|
||||
private TestPlanReportService testPlanReportService;
|
||||
@Resource
|
||||
private RedisTemplate<String, String> redisTemplate;
|
||||
private StringRedisTemplate stringRedisTemplate;
|
||||
@Resource
|
||||
private TestPlanReportApiCaseMapper testPlanReportApiCaseMapper;
|
||||
@Resource
|
||||
|
@ -47,14 +48,14 @@ public class TestPlanExecuteSupportService {
|
|||
|
||||
|
||||
public void setRedisForList(String key, List<String> list) {
|
||||
redisTemplate.opsForList().rightPushAll(key, list);
|
||||
redisTemplate.expire(key, 1, TimeUnit.DAYS);
|
||||
stringRedisTemplate.opsForList().rightPushAll(key, list);
|
||||
stringRedisTemplate.expire(key, 1, TimeUnit.DAYS);
|
||||
}
|
||||
|
||||
public void deleteRedisKey(String redisKey) {
|
||||
//清除list的key 和 last key节点
|
||||
redisTemplate.delete(redisKey);
|
||||
redisTemplate.delete(genQueueKey(redisKey, LAST_QUEUE_PREFIX));
|
||||
stringRedisTemplate.delete(redisKey);
|
||||
stringRedisTemplate.delete(genQueueKey(redisKey, LAST_QUEUE_PREFIX));
|
||||
}
|
||||
|
||||
@Transactional(propagation = Propagation.NOT_SUPPORTED)
|
||||
|
@ -105,7 +106,7 @@ public class TestPlanExecuteSupportService {
|
|||
}
|
||||
|
||||
String queueKey = this.genQueueKey(queueId, queueType);
|
||||
ListOperations<String, String> listOps = redisTemplate.opsForList();
|
||||
ListOperations<String, String> listOps = stringRedisTemplate.opsForList();
|
||||
String queueDetail = listOps.leftPop(queueKey);
|
||||
if (StringUtils.isBlank(queueDetail)) {
|
||||
// 重试1次获取
|
||||
|
@ -113,7 +114,7 @@ public class TestPlanExecuteSupportService {
|
|||
Thread.sleep(1000);
|
||||
} catch (Exception ignore) {
|
||||
}
|
||||
queueDetail = redisTemplate.opsForList().leftPop(queueKey);
|
||||
queueDetail = stringRedisTemplate.opsForList().leftPop(queueKey);
|
||||
}
|
||||
|
||||
if (StringUtils.isNotBlank(queueDetail)) {
|
||||
|
@ -123,14 +124,14 @@ public class TestPlanExecuteSupportService {
|
|||
returnQueue.setLastOne(true);
|
||||
if (StringUtils.equalsIgnoreCase(returnQueue.getRunMode(), ApiBatchRunMode.SERIAL.name())) {
|
||||
//串行的执行方式意味着最后一个节点要单独存储
|
||||
redisTemplate.opsForValue().setIfAbsent(genQueueKey(queueKey, LAST_QUEUE_PREFIX), JSON.toJSONString(returnQueue), 1, TimeUnit.DAYS);
|
||||
stringRedisTemplate.opsForValue().setIfAbsent(genQueueKey(queueKey, LAST_QUEUE_PREFIX), JSON.toJSONString(returnQueue), 1, TimeUnit.DAYS);
|
||||
}
|
||||
// 最后一个节点清理队列
|
||||
deleteQueue(queueKey);
|
||||
}
|
||||
return returnQueue;
|
||||
} else {
|
||||
String lastQueueJson = redisTemplate.opsForValue().getAndDelete(genQueueKey(queueKey, LAST_QUEUE_PREFIX));
|
||||
String lastQueueJson = stringRedisTemplate.opsForValue().getAndDelete(genQueueKey(queueKey, LAST_QUEUE_PREFIX));
|
||||
if (StringUtils.isNotBlank(lastQueueJson)) {
|
||||
TestPlanExecutionQueue nextQueue = JSON.parseObject(lastQueueJson, TestPlanExecutionQueue.class);
|
||||
nextQueue.setExecuteFinish(true);
|
||||
|
@ -144,8 +145,12 @@ public class TestPlanExecuteSupportService {
|
|||
}
|
||||
|
||||
|
||||
public void deleteQueue(String queueKey) {
|
||||
redisTemplate.delete(queueKey);
|
||||
public Boolean deleteQueue(String queueKey) {
|
||||
return stringRedisTemplate.delete(queueKey);
|
||||
}
|
||||
|
||||
public Set<String> keys(String queueKey) {
|
||||
return stringRedisTemplate.keys(queueKey);
|
||||
}
|
||||
|
||||
//生成队列key
|
||||
|
|
|
@ -254,7 +254,7 @@ public class TestPlanTaskCenterService {
|
|||
}
|
||||
|
||||
private void stopApiTask(TaskCenterBatchRequest request, List<String> projectIds, String userId, String module) {
|
||||
List<ReportDTO> reports = new ArrayList<>();
|
||||
List<ReportDTO> reports;
|
||||
if (request.isSelectAll()) {
|
||||
reports = extTestPlanReportMapper.getReports(request, projectIds, null, DateUtils.getDailyStartTime(), DateUtils.getDailyEndTime());
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue