fix(接口测试): 任务停止,资源池异常,无法停止成功
--bug=1047966 --user=陈建星 【任务中心】-执行测试计划,在任务中心停止正在执行的任务,停止失败,提示资源池不存在 https://www.tapd.cn/55049933/s/1598605
This commit is contained in:
parent
e979625b69
commit
db96c49133
|
@ -123,7 +123,7 @@ public class ApiTestCaseBatchRunService {
|
||||||
|
|
||||||
// 分批查询
|
// 分批查询
|
||||||
SubListUtils.dealForSubList(ids, TASK_BATCH_SIZE, subIds -> {
|
SubListUtils.dealForSubList(ids, TASK_BATCH_SIZE, subIds -> {
|
||||||
List<ApiTestCase> apiTestCases = getOrderApiTestCases(subIds, runModeConfig);
|
List<ApiTestCase> apiTestCases = getOrderApiTestCases(subIds);
|
||||||
|
|
||||||
// 初始化任务项
|
// 初始化任务项
|
||||||
List<ExecTaskItem> execTaskItems = initExecTaskItem(apiTestCases, userId, project, execTask);
|
List<ExecTaskItem> execTaskItems = initExecTaskItem(apiTestCases, userId, project, execTask);
|
||||||
|
@ -199,7 +199,7 @@ public class ApiTestCaseBatchRunService {
|
||||||
|
|
||||||
// 分批查询
|
// 分批查询
|
||||||
SubListUtils.dealForSubList(ids, TASK_BATCH_SIZE, subIds -> {
|
SubListUtils.dealForSubList(ids, TASK_BATCH_SIZE, subIds -> {
|
||||||
List<ApiTestCase> apiTestCases = getOrderApiTestCases(subIds, runModeConfig);
|
List<ApiTestCase> apiTestCases = getOrderApiTestCases(subIds);
|
||||||
// 初始化任务项
|
// 初始化任务项
|
||||||
Map<String, String> resourceExecTaskItemMap = initExecTaskItem(apiTestCases, userId, project, execTask)
|
Map<String, String> resourceExecTaskItemMap = initExecTaskItem(apiTestCases, userId, project, execTask)
|
||||||
.stream()
|
.stream()
|
||||||
|
@ -239,7 +239,7 @@ public class ApiTestCaseBatchRunService {
|
||||||
* @param ids
|
* @param ids
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private List<ApiTestCase> getOrderApiTestCases(List<String> ids, ApiRunModeConfigDTO runModeConfig) {
|
private List<ApiTestCase> getOrderApiTestCases(List<String> ids) {
|
||||||
List<ApiTestCase> apiTestCases = new ArrayList<>(TASK_BATCH_SIZE);
|
List<ApiTestCase> apiTestCases = new ArrayList<>(TASK_BATCH_SIZE);
|
||||||
// 分批查询
|
// 分批查询
|
||||||
List<ApiTestCase> finalApiTestCases = apiTestCases;
|
List<ApiTestCase> finalApiTestCases = apiTestCases;
|
||||||
|
@ -253,10 +253,6 @@ public class ApiTestCaseBatchRunService {
|
||||||
// 按照ID顺序排序
|
// 按照ID顺序排序
|
||||||
ApiTestCase apiTestCase = apiCaseMap.get(id);
|
ApiTestCase apiTestCase = apiCaseMap.get(id);
|
||||||
if (apiTestCase == null) {
|
if (apiTestCase == null) {
|
||||||
if (runModeConfig.isIntegratedReport()) {
|
|
||||||
// 用例不存在,则在执行集合中删除
|
|
||||||
apiExecutionSetService.removeItem(runModeConfig.getCollectionReport().getReportId(), id);
|
|
||||||
}
|
|
||||||
LogUtils.info("当前执行任务的用例已删除 {}", id);
|
LogUtils.info("当前执行任务的用例已删除 {}", id);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -127,7 +127,7 @@ public class ApiScenarioBatchRunService {
|
||||||
|
|
||||||
// 分批查询
|
// 分批查询
|
||||||
SubListUtils.dealForSubList(ids, TASK_BATCH_SIZE, subIds -> {
|
SubListUtils.dealForSubList(ids, TASK_BATCH_SIZE, subIds -> {
|
||||||
List<ApiScenario> apiScenarios = getOrderScenarios(subIds, runModeConfig);
|
List<ApiScenario> apiScenarios = getOrderScenarios(subIds);
|
||||||
|
|
||||||
// 初始化任务项
|
// 初始化任务项
|
||||||
List<ExecTaskItem> execTaskItems = initExecTaskItem(subIds, apiScenarios, userId, project, execTask);
|
List<ExecTaskItem> execTaskItems = initExecTaskItem(subIds, apiScenarios, userId, project, execTask);
|
||||||
|
@ -171,7 +171,7 @@ public class ApiScenarioBatchRunService {
|
||||||
|
|
||||||
// 分批查询
|
// 分批查询
|
||||||
SubListUtils.dealForSubList(ids, TASK_BATCH_SIZE, subIds -> {
|
SubListUtils.dealForSubList(ids, TASK_BATCH_SIZE, subIds -> {
|
||||||
List<ApiScenario> apiScenarios = getOrderScenarios(subIds, runModeConfig);
|
List<ApiScenario> apiScenarios = getOrderScenarios(subIds);
|
||||||
Map<String, String> caseReportMap = null;
|
Map<String, String> caseReportMap = null;
|
||||||
|
|
||||||
// 初始化任务项
|
// 初始化任务项
|
||||||
|
@ -218,7 +218,7 @@ public class ApiScenarioBatchRunService {
|
||||||
* @param ids
|
* @param ids
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private List<ApiScenario> getOrderScenarios(List<String> ids, ApiRunModeConfigDTO runModeConfig) {
|
private List<ApiScenario> getOrderScenarios(List<String> ids) {
|
||||||
List<ApiScenario> apiScenarios = new ArrayList<>(TASK_BATCH_SIZE);
|
List<ApiScenario> apiScenarios = new ArrayList<>(TASK_BATCH_SIZE);
|
||||||
// 分批查询
|
// 分批查询
|
||||||
List<ApiScenario> finalApiScenarios = apiScenarios;
|
List<ApiScenario> finalApiScenarios = apiScenarios;
|
||||||
|
@ -232,10 +232,6 @@ public class ApiScenarioBatchRunService {
|
||||||
// 按照ID顺序排序
|
// 按照ID顺序排序
|
||||||
ApiScenario apiScenario = apiScenarioMap.get(id);
|
ApiScenario apiScenario = apiScenarioMap.get(id);
|
||||||
if (apiScenario == null) {
|
if (apiScenario == null) {
|
||||||
if (runModeConfig.isIntegratedReport()) {
|
|
||||||
// 用例不存在,则在执行集合中删除
|
|
||||||
apiExecutionSetService.removeItem(runModeConfig.getCollectionReport().getReportId(), id);
|
|
||||||
}
|
|
||||||
LogUtils.info("当前执行任务的用例已删除 {}", id);
|
LogUtils.info("当前执行任务的用例已删除 {}", id);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -300,7 +300,6 @@ public class ApiScenarioRunService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public GetRunScriptResult getRunScript(GetRunScriptRequest request, ApiScenarioDetail apiScenarioDetail) {
|
public GetRunScriptResult getRunScript(GetRunScriptRequest request, ApiScenarioDetail apiScenarioDetail) {
|
||||||
String id = apiScenarioDetail.getId();
|
|
||||||
TaskItem taskItem = request.getTaskItem();
|
TaskItem taskItem = request.getTaskItem();
|
||||||
ApiRunModeConfigDTO runModeConfig = request.getRunModeConfig();
|
ApiRunModeConfigDTO runModeConfig = request.getRunModeConfig();
|
||||||
String reportId = taskItem.getReportId();
|
String reportId = taskItem.getReportId();
|
||||||
|
@ -308,9 +307,9 @@ public class ApiScenarioRunService {
|
||||||
if (apiScenarioDetail == null) {
|
if (apiScenarioDetail == null) {
|
||||||
if (runModeConfig.isIntegratedReport()) {
|
if (runModeConfig.isIntegratedReport()) {
|
||||||
// 用例不存在,则在执行集合中删除
|
// 用例不存在,则在执行集合中删除
|
||||||
apiExecutionSetService.removeItem(runModeConfig.getCollectionReport().getReportId(), id);
|
apiExecutionSetService.removeItem(request.getTaskId(), taskItem.getId());
|
||||||
}
|
}
|
||||||
LogUtils.info("当前执行任务的用例已删除 {}", id);
|
LogUtils.info("当前执行任务的用例已删除 {}", taskItem.getId());
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -582,7 +582,11 @@ public class BaseTaskHubService {
|
||||||
|
|
||||||
//2.更新任务明细状态
|
//2.更新任务明细状态
|
||||||
extExecTaskItemMapper.batchUpdateTaskItemStatus(List.of(id), userId, orgId, projectId, ExecStatus.STOPPED.name());
|
extExecTaskItemMapper.batchUpdateTaskItemStatus(List.of(id), userId, orgId, projectId, ExecStatus.STOPPED.name());
|
||||||
handleStopTask(List.of(id));
|
handleStopTaskAsync(List.of(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleStopTaskAsync(List<String> ids) {
|
||||||
|
Thread.startVirtualThread(() -> handleStopTask(ids));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleStopTask(List<String> ids) {
|
private void handleStopTask(List<String> ids) {
|
||||||
|
@ -590,6 +594,7 @@ public class BaseTaskHubService {
|
||||||
List<ExecTaskItem> list = extExecTaskItemMapper.getResourcePoolsByTaskIds(ids);
|
List<ExecTaskItem> list = extExecTaskItemMapper.getResourcePoolsByTaskIds(ids);
|
||||||
Map<String, List<ExecTaskItem>> resourcePoolMaps = list.stream().collect(Collectors.groupingBy(ExecTaskItem::getResourcePoolId));
|
Map<String, List<ExecTaskItem>> resourcePoolMaps = list.stream().collect(Collectors.groupingBy(ExecTaskItem::getResourcePoolId));
|
||||||
resourcePoolMaps.forEach((k, v) -> {
|
resourcePoolMaps.forEach((k, v) -> {
|
||||||
|
try {
|
||||||
//判断资源池类型
|
//判断资源池类型
|
||||||
TestResourcePoolReturnDTO testResourcePoolDTO = testResourcePoolService.getTestResourcePoolDetail(k);
|
TestResourcePoolReturnDTO testResourcePoolDTO = testResourcePoolService.getTestResourcePoolDetail(k);
|
||||||
boolean isK8SResourcePool = StringUtils.equals(testResourcePoolDTO.getType(), ResourcePoolTypeEnum.K8S.getName());
|
boolean isK8SResourcePool = StringUtils.equals(testResourcePoolDTO.getType(), ResourcePoolTypeEnum.K8S.getName());
|
||||||
|
@ -601,6 +606,9 @@ public class BaseTaskHubService {
|
||||||
Map<String, List<ExecTaskItem>> nodeItem = list.stream().collect(Collectors.groupingBy(ExecTaskItem::getResourcePoolNode));
|
Map<String, List<ExecTaskItem>> nodeItem = list.stream().collect(Collectors.groupingBy(ExecTaskItem::getResourcePoolNode));
|
||||||
handleNodeTask(nodeItem);
|
handleNodeTask(nodeItem);
|
||||||
}
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
LogUtils.error(e);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -640,7 +648,7 @@ public class BaseTaskHubService {
|
||||||
execTaskItemMapper.deleteByExample(itemExample);
|
execTaskItemMapper.deleteByExample(itemExample);
|
||||||
//3.删除任务与报告关联关系
|
//3.删除任务与报告关联关系
|
||||||
deleteReportRelateTask(List.of(id));
|
deleteReportRelateTask(List.of(id));
|
||||||
handleStopTask(List.of(id));
|
handleStopTaskAsync(List.of(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void deleteReportRelateTask(List<String> ids) {
|
private void deleteReportRelateTask(List<String> ids) {
|
||||||
|
@ -657,7 +665,7 @@ public class BaseTaskHubService {
|
||||||
extExecTaskMapper.batchUpdateTaskStatus(ids, userId, orgId, projectId, ExecStatus.STOPPED.name());
|
extExecTaskMapper.batchUpdateTaskStatus(ids, userId, orgId, projectId, ExecStatus.STOPPED.name());
|
||||||
//2.更新任务明细状态
|
//2.更新任务明细状态
|
||||||
extExecTaskItemMapper.batchUpdateTaskItemStatus(ids, userId, orgId, projectId, ExecStatus.STOPPED.name());
|
extExecTaskItemMapper.batchUpdateTaskItemStatus(ids, userId, orgId, projectId, ExecStatus.STOPPED.name());
|
||||||
handleStopTask(ids);
|
handleStopTaskAsync(ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -684,7 +692,7 @@ public class BaseTaskHubService {
|
||||||
execTaskItemMapper.deleteByExample(itemExample);
|
execTaskItemMapper.deleteByExample(itemExample);
|
||||||
//3.删除任务与报告关联关系
|
//3.删除任务与报告关联关系
|
||||||
deleteReportRelateTask(ids);
|
deleteReportRelateTask(ids);
|
||||||
handleStopTask(ids);
|
handleStopTaskAsync(ids);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -700,14 +708,18 @@ public class BaseTaskHubService {
|
||||||
//1.更新任务明细状态
|
//1.更新任务明细状态
|
||||||
extExecTaskItemMapper.batchUpdateTaskItemStatusByIds(List.of(id), userId, orgId, projectId, ExecStatus.STOPPED.name());
|
extExecTaskItemMapper.batchUpdateTaskItemStatusByIds(List.of(id), userId, orgId, projectId, ExecStatus.STOPPED.name());
|
||||||
//2.通过任务项id停止任务
|
//2.通过任务项id停止任务
|
||||||
handleStopTaskItem(List.of(id));
|
handleStopTaskItemAsync(List.of(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void handleStopTaskItemAsync(List<String> ids) {
|
||||||
|
Thread.startVirtualThread(() -> handleStopTaskItem(ids));
|
||||||
|
}
|
||||||
|
|
||||||
private void handleStopTaskItem(List<String> ids) {
|
private void handleStopTaskItem(List<String> ids) {
|
||||||
List<ExecTaskItem> execTaskItems = extExecTaskItemMapper.getResourcePoolsByItemIds(ids);
|
List<ExecTaskItem> execTaskItems = extExecTaskItemMapper.getResourcePoolsByItemIds(ids);
|
||||||
Map<String, List<ExecTaskItem>> resourcePoolMaps = execTaskItems.stream().collect(Collectors.groupingBy(ExecTaskItem::getResourcePoolId));
|
Map<String, List<ExecTaskItem>> resourcePoolMaps = execTaskItems.stream().collect(Collectors.groupingBy(ExecTaskItem::getResourcePoolId));
|
||||||
resourcePoolMaps.forEach((k, v) -> {
|
resourcePoolMaps.forEach((k, v) -> {
|
||||||
|
try {
|
||||||
//判断资源池类型
|
//判断资源池类型
|
||||||
TestResourcePoolReturnDTO testResourcePoolDTO = testResourcePoolService.getTestResourcePoolDetail(k);
|
TestResourcePoolReturnDTO testResourcePoolDTO = testResourcePoolService.getTestResourcePoolDetail(k);
|
||||||
boolean isK8SResourcePool = StringUtils.equals(testResourcePoolDTO.getType(), ResourcePoolTypeEnum.K8S.getName());
|
boolean isK8SResourcePool = StringUtils.equals(testResourcePoolDTO.getType(), ResourcePoolTypeEnum.K8S.getName());
|
||||||
|
@ -719,6 +731,9 @@ public class BaseTaskHubService {
|
||||||
Map<String, List<ExecTaskItem>> nodeItem = execTaskItems.stream().collect(Collectors.groupingBy(ExecTaskItem::getResourcePoolNode));
|
Map<String, List<ExecTaskItem>> nodeItem = execTaskItems.stream().collect(Collectors.groupingBy(ExecTaskItem::getResourcePoolNode));
|
||||||
handleNodeTask(nodeItem);
|
handleNodeTask(nodeItem);
|
||||||
}
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
LogUtils.error(e);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -739,7 +754,7 @@ public class BaseTaskHubService {
|
||||||
//1.更新任务明细状态
|
//1.更新任务明细状态
|
||||||
extExecTaskItemMapper.batchUpdateTaskItemStatusByIds(itemIds, userId, orgId, projectId, ExecStatus.STOPPED.name());
|
extExecTaskItemMapper.batchUpdateTaskItemStatusByIds(itemIds, userId, orgId, projectId, ExecStatus.STOPPED.name());
|
||||||
//2.通过任务项id停止任务
|
//2.通过任务项id停止任务
|
||||||
handleStopTaskItem(itemIds);
|
handleStopTaskItemAsync(itemIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue