fix(接口测试): 资源池不可用,清理执行队列等信息
--bug=1049133 --user=陈建星 【任务中心】-计划组的部分子计划关联的资源池不可用,失败重跑时,任务无法执行完成 https://www.tapd.cn/55049933/s/1616882
This commit is contained in:
parent
2c40fc7757
commit
22f95f84a5
|
@ -5,6 +5,7 @@ import io.metersphere.api.domain.ApiReportRelateTaskExample;
|
||||||
import io.metersphere.api.domain.ApiScenarioReport;
|
import io.metersphere.api.domain.ApiScenarioReport;
|
||||||
import io.metersphere.api.mapper.ApiReportRelateTaskMapper;
|
import io.metersphere.api.mapper.ApiReportRelateTaskMapper;
|
||||||
import io.metersphere.api.service.queue.ApiExecutionQueueService;
|
import io.metersphere.api.service.queue.ApiExecutionQueueService;
|
||||||
|
import io.metersphere.api.service.queue.ApiExecutionSetService;
|
||||||
import io.metersphere.sdk.constants.ApiBatchRunMode;
|
import io.metersphere.sdk.constants.ApiBatchRunMode;
|
||||||
import io.metersphere.sdk.constants.CommonConstants;
|
import io.metersphere.sdk.constants.CommonConstants;
|
||||||
import io.metersphere.sdk.constants.ExecStatus;
|
import io.metersphere.sdk.constants.ExecStatus;
|
||||||
|
@ -47,6 +48,8 @@ public class ApiBatchRunBaseService {
|
||||||
private ExecTaskMapper execTaskMapper;
|
private ExecTaskMapper execTaskMapper;
|
||||||
@Resource
|
@Resource
|
||||||
private ApiReportRelateTaskMapper apiReportRelateTaskMapper;
|
private ApiReportRelateTaskMapper apiReportRelateTaskMapper;
|
||||||
|
@Resource
|
||||||
|
private ApiExecutionSetService apiExecutionSetService;
|
||||||
|
|
||||||
public static final int BATCH_TASK_ITEM_SIZE = 500;
|
public static final int BATCH_TASK_ITEM_SIZE = 500;
|
||||||
|
|
||||||
|
@ -271,7 +274,14 @@ public class ApiBatchRunBaseService {
|
||||||
|
|
||||||
if (count > 0) {
|
if (count > 0) {
|
||||||
taskRequest.setTaskItems(taskItems);
|
taskRequest.setTaskItems(taskItems);
|
||||||
|
try {
|
||||||
apiExecuteService.batchExecute(taskRequest);
|
apiExecuteService.batchExecute(taskRequest);
|
||||||
|
} catch (Exception e) {
|
||||||
|
// 执行失败,删除执行集合中的任务项
|
||||||
|
List<String> taskItemIds = taskRequest.getTaskItems().stream().map(TaskItem::getId).toList();
|
||||||
|
apiExecutionSetService.removeItems(taskRequest.getTaskInfo().getSetId(), taskItemIds);
|
||||||
|
LogUtils.error(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -395,7 +395,12 @@ public class ApiTestCaseBatchRunService {
|
||||||
taskRequest.getTaskItem().setRequestCount(1L);
|
taskRequest.getTaskItem().setRequestCount(1L);
|
||||||
taskRequest.getTaskItem().setId(taskItemId);
|
taskRequest.getTaskItem().setId(taskItemId);
|
||||||
|
|
||||||
|
try {
|
||||||
apiExecuteService.execute(taskRequest);
|
apiExecuteService.execute(taskRequest);
|
||||||
|
} catch (Exception e) {
|
||||||
|
// 执行失败,删除队列
|
||||||
|
apiExecutionQueueService.deleteQueue(queue.getQueueId());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private TaskRequestDTO getTaskRequestDTO(String reportId, ApiTestCase apiTestCase, ApiRunModeConfigDTO runModeConfig) {
|
private TaskRequestDTO getTaskRequestDTO(String reportId, ApiTestCase apiTestCase, ApiRunModeConfigDTO runModeConfig) {
|
||||||
|
|
|
@ -34,8 +34,21 @@ public class ApiExecutionSetService {
|
||||||
/**
|
/**
|
||||||
* 从执行集合中去除选项
|
* 从执行集合中去除选项
|
||||||
*/
|
*/
|
||||||
public Long removeItem(String setId, String resourceId) {
|
public Long removeItem(String setId, String taskItemId) {
|
||||||
stringRedisTemplate.opsForSet().remove(SET_PREFIX + setId, resourceId);
|
stringRedisTemplate.opsForSet().remove(SET_PREFIX + setId, taskItemId);
|
||||||
|
Long size = stringRedisTemplate.opsForSet().size(SET_PREFIX + setId);
|
||||||
|
if (size == null || size == 0) {
|
||||||
|
// 集合没有元素,则删除集合
|
||||||
|
stringRedisTemplate.delete(SET_PREFIX + setId);
|
||||||
|
}
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从执行集合中去除选项
|
||||||
|
*/
|
||||||
|
public Long removeItems(String setId, List<String> taskItemIds) {
|
||||||
|
stringRedisTemplate.opsForSet().remove(SET_PREFIX + setId, taskItemIds.toArray());
|
||||||
Long size = stringRedisTemplate.opsForSet().size(SET_PREFIX + setId);
|
Long size = stringRedisTemplate.opsForSet().size(SET_PREFIX + setId);
|
||||||
if (size == null || size == 0) {
|
if (size == null || size == 0) {
|
||||||
// 集合没有元素,则删除集合
|
// 集合没有元素,则删除集合
|
||||||
|
|
|
@ -351,7 +351,12 @@ public class ApiScenarioBatchRunService {
|
||||||
taskRequest.getTaskInfo().setTaskId(queue.getTaskId());
|
taskRequest.getTaskInfo().setTaskId(queue.getTaskId());
|
||||||
taskRequest.getTaskInfo().setRerun(queue.getRerun());
|
taskRequest.getTaskInfo().setRerun(queue.getRerun());
|
||||||
|
|
||||||
|
try {
|
||||||
apiExecuteService.execute(taskRequest);
|
apiExecuteService.execute(taskRequest);
|
||||||
|
} catch (Exception e) {
|
||||||
|
// 执行失败,删除队列
|
||||||
|
apiExecutionQueueService.deleteQueue(queue.getQueueId());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private TaskRequestDTO getTaskRequestDTO(String projectId, ApiRunModeConfigDTO runModeConfig) {
|
private TaskRequestDTO getTaskRequestDTO(String projectId, ApiRunModeConfigDTO runModeConfig) {
|
||||||
|
|
|
@ -116,12 +116,13 @@ public class PlanRunTestPlanApiCaseService {
|
||||||
|
|
||||||
TestPlan testPlan = testPlanMapper.selectByPrimaryKey(testPlanId);
|
TestPlan testPlan = testPlanMapper.selectByPrimaryKey(testPlanId);
|
||||||
TaskBatchRequestDTO taskRequest = apiTestCaseBatchRunService.getTaskBatchRequestDTO(testPlan.getProjectId(), runModeConfig);
|
TaskBatchRequestDTO taskRequest = apiTestCaseBatchRunService.getTaskBatchRequestDTO(testPlan.getProjectId(), runModeConfig);
|
||||||
taskRequest.getTaskInfo().setTaskId(taskId);
|
TaskInfo taskInfo = taskRequest.getTaskInfo();
|
||||||
taskRequest.getTaskInfo().setParentQueueId(testPlanExecutionQueue.getQueueId());
|
taskInfo.setTaskId(taskId);
|
||||||
taskRequest.getTaskInfo().setSetId(execSetId);
|
taskInfo.setParentQueueId(testPlanExecutionQueue.getQueueId());
|
||||||
taskRequest.getTaskInfo().setRerun(testPlanExecutionQueue.isRerun());
|
taskInfo.setSetId(execSetId);
|
||||||
taskRequest.getTaskInfo().setUserId(userId);
|
taskInfo.setRerun(testPlanExecutionQueue.isRerun());
|
||||||
taskRequest.getTaskInfo().setResourceType(ApiExecuteResourceType.PLAN_RUN_API_CASE.name());
|
taskInfo.setUserId(userId);
|
||||||
|
taskInfo.setResourceType(ApiExecuteResourceType.PLAN_RUN_API_CASE.name());
|
||||||
|
|
||||||
List<ExecTaskItem> execTaskItems = apiBatchRunBaseService.getExecTaskItemByTaskIdAndCollectionId(testPlanExecutionQueue.getTaskId(),
|
List<ExecTaskItem> execTaskItems = apiBatchRunBaseService.getExecTaskItemByTaskIdAndCollectionId(testPlanExecutionQueue.getTaskId(),
|
||||||
collection.getId(), testPlanExecutionQueue.isRerun());
|
collection.getId(), testPlanExecutionQueue.isRerun());
|
||||||
|
@ -141,10 +142,17 @@ public class PlanRunTestPlanApiCaseService {
|
||||||
})
|
})
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
List<String> taskItemIds = taskItems.stream().map(TaskItem::getId).toList();
|
||||||
// 初始化执行集合,以便判断是否执行完毕
|
// 初始化执行集合,以便判断是否执行完毕
|
||||||
apiExecutionSetService.initSet(execSetId, taskItems.stream().map(TaskItem::getId).toList());
|
apiExecutionSetService.initSet(execSetId, taskItemIds);
|
||||||
taskRequest.setTaskItems(taskItems);
|
taskRequest.setTaskItems(taskItems);
|
||||||
|
try {
|
||||||
apiExecuteService.batchExecute(taskRequest);
|
apiExecuteService.batchExecute(taskRequest);
|
||||||
|
} catch (Exception e) {
|
||||||
|
// 执行失败,删除执行集合中的任务项
|
||||||
|
apiExecutionSetService.removeItems(execSetId, taskItemIds);
|
||||||
|
LogUtils.error(e);
|
||||||
|
}
|
||||||
taskRequest.setTaskItems(null);
|
taskRequest.setTaskItems(null);
|
||||||
});
|
});
|
||||||
return false;
|
return false;
|
||||||
|
@ -180,7 +188,12 @@ public class PlanRunTestPlanApiCaseService {
|
||||||
taskRequest.getTaskItem().setRequestCount(1L);
|
taskRequest.getTaskItem().setRequestCount(1L);
|
||||||
taskRequest.getTaskItem().setId(queueDetail.getTaskItemId());
|
taskRequest.getTaskItem().setId(queueDetail.getTaskItemId());
|
||||||
|
|
||||||
|
try {
|
||||||
apiExecuteService.execute(taskRequest);
|
apiExecuteService.execute(taskRequest);
|
||||||
|
} catch (Exception e) {
|
||||||
|
// 执行失败,删除队列
|
||||||
|
apiExecutionQueueService.deleteQueue(queue.getQueueId());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -135,10 +135,18 @@ public class PlanRunTestPlanApiScenarioService {
|
||||||
})
|
})
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
List<String> taskItemIds = taskItems.stream().map(TaskItem::getId).toList();
|
||||||
|
|
||||||
// 初始化执行集合,以便判断是否执行完毕
|
// 初始化执行集合,以便判断是否执行完毕
|
||||||
apiExecutionSetService.initSet(execSetId, taskItems.stream().map(TaskItem::getId).toList());
|
apiExecutionSetService.initSet(execSetId, taskItemIds);
|
||||||
taskRequest.setTaskItems(taskItems);
|
taskRequest.setTaskItems(taskItems);
|
||||||
|
try {
|
||||||
apiExecuteService.batchExecute(taskRequest);
|
apiExecuteService.batchExecute(taskRequest);
|
||||||
|
} catch (Exception e) {
|
||||||
|
// 执行失败,删除执行集合中的任务项
|
||||||
|
apiExecutionSetService.removeItems(execSetId, taskItemIds);
|
||||||
|
LogUtils.error(e);
|
||||||
|
}
|
||||||
taskRequest.setTaskItems(null);
|
taskRequest.setTaskItems(null);
|
||||||
});
|
});
|
||||||
return false;
|
return false;
|
||||||
|
@ -186,8 +194,12 @@ public class PlanRunTestPlanApiScenarioService {
|
||||||
taskRequest.getTaskInfo().setRerun(queue.getRerun());
|
taskRequest.getTaskInfo().setRerun(queue.getRerun());
|
||||||
taskRequest.getTaskInfo().setParentQueueId(queue.getParentQueueId());
|
taskRequest.getTaskInfo().setParentQueueId(queue.getParentQueueId());
|
||||||
taskRequest.getTaskInfo().setResourceType(ApiExecuteResourceType.PLAN_RUN_API_SCENARIO.name());
|
taskRequest.getTaskInfo().setResourceType(ApiExecuteResourceType.PLAN_RUN_API_SCENARIO.name());
|
||||||
|
try {
|
||||||
apiExecuteService.execute(taskRequest);
|
apiExecuteService.execute(taskRequest);
|
||||||
|
} catch (Exception e) {
|
||||||
|
// 执行失败,删除队列
|
||||||
|
apiExecutionQueueService.deleteQueue(queue.getQueueId());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public GetRunScriptResult getRunScript(GetRunScriptRequest request) {
|
public GetRunScriptResult getRunScript(GetRunScriptRequest request) {
|
||||||
|
|
|
@ -250,14 +250,24 @@ public class TestPlanApiCaseBatchRunService {
|
||||||
})
|
})
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
List<String> taskIds = taskItems.stream().map(TaskItem::getId).toList();
|
List<String> taskItemIds = taskItems.stream().map(TaskItem::getId).toList();
|
||||||
|
|
||||||
if (StringUtils.isBlank(parentSetId)) {
|
if (StringUtils.isBlank(parentSetId)) {
|
||||||
// 如果有没有父集合,则初始化执行集合,以便判断是否执行完毕
|
// 如果有没有父集合,则初始化执行集合,以便判断是否执行完毕
|
||||||
apiExecutionSetService.initSet(taskInfo.getSetId(), taskIds);
|
apiExecutionSetService.initSet(taskInfo.getSetId(), taskItemIds);
|
||||||
}
|
}
|
||||||
taskRequest.setTaskItems(taskItems);
|
taskRequest.setTaskItems(taskItems);
|
||||||
|
|
||||||
|
try {
|
||||||
apiExecuteService.batchExecute(taskRequest);
|
apiExecuteService.batchExecute(taskRequest);
|
||||||
|
} catch (Exception e) {
|
||||||
|
// 执行失败,删除执行集合中的任务项
|
||||||
|
if (StringUtils.isBlank(parentSetId)) {
|
||||||
|
apiExecutionSetService.removeItems(taskInfo.getSetId(), taskItemIds);
|
||||||
|
}
|
||||||
|
LogUtils.error(e);
|
||||||
|
}
|
||||||
|
|
||||||
taskRequest.setTaskItems(null);
|
taskRequest.setTaskItems(null);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -347,7 +357,13 @@ public class TestPlanApiCaseBatchRunService {
|
||||||
taskRequest.getTaskItem().setId(queueDetail.getTaskItemId());
|
taskRequest.getTaskItem().setId(queueDetail.getTaskItemId());
|
||||||
taskRequest.getTaskItem().setRequestCount(1L);
|
taskRequest.getTaskItem().setRequestCount(1L);
|
||||||
|
|
||||||
|
try {
|
||||||
apiExecuteService.execute(taskRequest);
|
apiExecuteService.execute(taskRequest);
|
||||||
|
} catch (Exception e) {
|
||||||
|
// 执行失败,删除队列
|
||||||
|
apiExecutionQueueService.deleteQueue(queue.getQueueId());
|
||||||
|
apiExecutionQueueService.deleteQueue(queue.getParentQueueId());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public TaskRequestDTO getTaskRequestDTO(String resourceId, ApiTestCase apiTestCase, ApiRunModeConfigDTO runModeConfig) {
|
public TaskRequestDTO getTaskRequestDTO(String resourceId, ApiTestCase apiTestCase, ApiRunModeConfigDTO runModeConfig) {
|
||||||
|
|
|
@ -25,6 +25,7 @@ import io.metersphere.sdk.dto.api.task.*;
|
||||||
import io.metersphere.sdk.dto.queue.ExecutionQueue;
|
import io.metersphere.sdk.dto.queue.ExecutionQueue;
|
||||||
import io.metersphere.sdk.dto.queue.ExecutionQueueDetail;
|
import io.metersphere.sdk.dto.queue.ExecutionQueueDetail;
|
||||||
import io.metersphere.sdk.util.CommonBeanFactory;
|
import io.metersphere.sdk.util.CommonBeanFactory;
|
||||||
|
import io.metersphere.sdk.util.LogUtils;
|
||||||
import io.metersphere.sdk.util.SubListUtils;
|
import io.metersphere.sdk.util.SubListUtils;
|
||||||
import io.metersphere.sdk.util.Translator;
|
import io.metersphere.sdk.util.Translator;
|
||||||
import io.metersphere.system.domain.ExecTask;
|
import io.metersphere.system.domain.ExecTask;
|
||||||
|
@ -258,14 +259,22 @@ public class TestPlanApiScenarioBatchRunService {
|
||||||
})
|
})
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
List<String> taskIds = taskItems.stream().map(TaskItem::getId).toList();
|
List<String> taskItemIds = taskItems.stream().map(TaskItem::getId).toList();
|
||||||
|
|
||||||
if (StringUtils.isBlank(parentSetId)) {
|
if (StringUtils.isBlank(parentSetId)) {
|
||||||
// 如果有没有父集合,则初始化执行集合,以便判断是否执行完毕
|
// 如果有没有父集合,则初始化执行集合,以便判断是否执行完毕
|
||||||
apiExecutionSetService.initSet(taskInfo.getSetId(), taskIds);
|
apiExecutionSetService.initSet(taskInfo.getSetId(), taskItemIds);
|
||||||
}
|
}
|
||||||
taskRequest.setTaskItems(taskItems);
|
taskRequest.setTaskItems(taskItems);
|
||||||
|
try {
|
||||||
apiExecuteService.batchExecute(taskRequest);
|
apiExecuteService.batchExecute(taskRequest);
|
||||||
|
} catch (Exception e) {
|
||||||
|
// 执行失败,删除执行集合中的任务项
|
||||||
|
if (StringUtils.isBlank(parentSetId)) {
|
||||||
|
apiExecutionSetService.removeItems(taskInfo.getSetId(), taskItemIds);
|
||||||
|
}
|
||||||
|
LogUtils.error(e);
|
||||||
|
}
|
||||||
taskRequest.setTaskItems(null);
|
taskRequest.setTaskItems(null);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -319,7 +328,13 @@ public class TestPlanApiScenarioBatchRunService {
|
||||||
taskRequest.getTaskInfo().setParentQueueId(queue.getParentQueueId());
|
taskRequest.getTaskInfo().setParentQueueId(queue.getParentQueueId());
|
||||||
taskRequest.getTaskInfo().setParentSetId(queue.getParentSetId());
|
taskRequest.getTaskInfo().setParentSetId(queue.getParentSetId());
|
||||||
|
|
||||||
|
try {
|
||||||
apiExecuteService.execute(taskRequest);
|
apiExecuteService.execute(taskRequest);
|
||||||
|
} catch (Exception e) {
|
||||||
|
// 执行失败,删除队列
|
||||||
|
apiExecutionQueueService.deleteQueue(queue.getQueueId());
|
||||||
|
apiExecutionQueueService.deleteQueue(queue.getParentQueueId());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public TaskRequestDTO getTaskRequestDTO(String projectId, ApiRunModeConfigDTO runModeConfig) {
|
public TaskRequestDTO getTaskRequestDTO(String projectId, ApiRunModeConfigDTO runModeConfig) {
|
||||||
|
|
Loading…
Reference in New Issue