fix(接口测试): 批量执行失败停止,没有更新任务状态

--bug=1047873 --user=陈建星 【任务中心】-批量执行场景,执行方式为串行+失败停止,批量执行任务不会自动停止,失败停止的场景处于等待排队状态 https://www.tapd.cn/55049933/s/1596875
This commit is contained in:
AgAngle 2024-10-24 11:36:33 +08:00 committed by Craftsman
parent d7d57690ce
commit 1d9c4b2af7
2 changed files with 20 additions and 6 deletions

View File

@ -3,6 +3,7 @@ package io.metersphere.api.listener;
import io.metersphere.api.invoker.ApiExecuteCallbackServiceInvoker;
import io.metersphere.api.mapper.ApiReportMapper;
import io.metersphere.api.mapper.ApiScenarioReportMapper;
import io.metersphere.api.service.ApiBatchRunBaseService;
import io.metersphere.api.service.ApiReportSendNoticeService;
import io.metersphere.api.service.definition.ApiTestCaseBatchRunService;
import io.metersphere.api.service.queue.ApiExecutionQueueService;
@ -30,10 +31,11 @@ public class MessageListener {
public static final String MESSAGE_CONSUME_ID = "MS-API-MESSAGE-CONSUME";
@Resource
private ApiReportSendNoticeService apiReportSendNoticeService;
@Resource
private ApiExecutionQueueService apiExecutionQueueService;
@Resource
private ApiBatchRunBaseService apiBatchRunBaseService;
@Resource
private ApiTestCaseBatchRunService apiTestCaseBatchRunService;
@Resource
private ApiScenarioBatchRunService apiScenarioBatchRunService;
@ -118,6 +120,10 @@ public class MessageListener {
}
if (isStopOnFailure(dto)) {
ApiExecuteResourceType resourceType = EnumValidator.validateEnum(ApiExecuteResourceType.class, queue.getResourceType());
if (resourceType != ApiExecuteResourceType.PLAN_RUN_API_SCENARIO && resourceType != ApiExecuteResourceType.PLAN_RUN_API_CASE) {
// 失败停止更新任务状态
apiBatchRunBaseService.updateTaskCompletedStatus(queue.getTaskId(), ResultStatus.ERROR.name());
}
// 补充集成报告
updateStopOnFailureIntegratedReport(dto, queue, resourceType);
// 如果是失败停止清空队列不继续执行

View File

@ -210,6 +210,10 @@ public class ApiBatchRunBaseService {
}
public void updateTaskCompletedStatus(String taskId) {
updateTaskCompletedStatus(taskId, null);
}
public void updateTaskCompletedStatus(String taskId, String result) {
// 删除执行缓存
removeRunningTaskCache(taskId);
ExecTask originExecTask = execTaskMapper.selectByPrimaryKey(taskId);
@ -220,12 +224,16 @@ public class ApiBatchRunBaseService {
execTask.setEndTime(System.currentTimeMillis());
execTask.setId(taskId);
execTask.setStatus(ExecStatus.COMPLETED.name());
if (extExecTaskItemMapper.hasErrorItem(taskId)) {
execTask.setResult(ResultStatus.ERROR.name());
} else if (extExecTaskItemMapper.hasFakeErrorItem(taskId)) {
execTask.setResult(ResultStatus.FAKE_ERROR.name());
if (StringUtils.isNotBlank(result)) {
execTask.setResult(result);
} else {
execTask.setResult(ResultStatus.SUCCESS.name());
if (extExecTaskItemMapper.hasErrorItem(taskId)) {
execTask.setResult(ResultStatus.ERROR.name());
} else if (extExecTaskItemMapper.hasFakeErrorItem(taskId)) {
execTask.setResult(ResultStatus.FAKE_ERROR.name());
} else {
execTask.setResult(ResultStatus.SUCCESS.name());
}
}
execTaskMapper.updateByPrimaryKeySelective(execTask);
}