From 6293dd63fafbeab8ac94558c4ee348b2a5c0758e Mon Sep 17 00:00:00 2001 From: AgAngle <1323481023@qq.com> Date: Wed, 23 Oct 2024 11:23:20 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E8=AE=A1=E5=88=92=E6=89=A7=E8=A1=8C=EF=BC=8C?= =?UTF-8?q?=E8=B5=84=E6=BA=90=E6=B1=A0=E4=B8=8D=E5=8F=AF=E7=94=A8=EF=BC=8C?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E7=8A=B6=E6=80=81=E6=98=BE=E7=A4=BA=E6=9C=89?= =?UTF-8?q?=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1047861 --user=陈建星 【测试计划】资源池被禁用-执行计划-任务数据问题汇总 https://www.tapd.cn/55049933/s/1596223 --- .../api/service/ApiBatchRunBaseService.java | 33 +++++++++++-------- .../TestPlanApiCaseBatchRunService.java | 3 +- .../TestPlanApiScenarioBatchRunService.java | 3 +- .../plan/service/TestPlanExecuteService.java | 3 +- 4 files changed, 23 insertions(+), 19 deletions(-) diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/ApiBatchRunBaseService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/ApiBatchRunBaseService.java index f1aa3fed1a..e5a0091e7c 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/ApiBatchRunBaseService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/ApiBatchRunBaseService.java @@ -209,24 +209,31 @@ public class ApiBatchRunBaseService { return runModeConfig.getEnvironmentId(); } - public void updateTaskStatus(String taskId) { - // 更新任务状态 - ExecTask execTask = new ExecTask(); - 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()); - } else { - execTask.setResult(ResultStatus.SUCCESS.name()); + public void updateTaskCompletedStatus(String taskId) { + // 删除执行缓存 + removeRunningTaskCache(taskId); + ExecTask originExecTask = execTaskMapper.selectByPrimaryKey(taskId); + // 出现异常,导致任务没有开始,则不更新任务状态 + if (!StringUtils.equals(originExecTask.getStatus(), ExecStatus.PENDING.name())) { + // 更新任务状态 + ExecTask execTask = new ExecTask(); + 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()); + } else { + execTask.setResult(ResultStatus.SUCCESS.name()); + } + execTaskMapper.updateByPrimaryKeySelective(execTask); } - execTaskMapper.updateByPrimaryKeySelective(execTask); } /** * 清理正在运行的任务缓存 + * * @param taskId */ public void removeRunningTaskCache(String taskId) { diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiCaseBatchRunService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiCaseBatchRunService.java index 77a90a7d3d..1082519195 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiCaseBatchRunService.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiCaseBatchRunService.java @@ -175,8 +175,7 @@ public class TestPlanApiCaseBatchRunService { ExecutionQueue collectionQueue = apiExecutionQueueService.getQueue(collectionQueueId); if (collectionQueue == null) { // 失败停止,或者执行完成,更新任务状态 - apiBatchRunBaseService.updateTaskStatus(collectionQueueId); - apiBatchRunBaseService.removeRunningTaskCache(collectionQueueId); + apiBatchRunBaseService.updateTaskCompletedStatus(collectionQueueId); return; } String userId = collectionQueue.getUserId(); diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiScenarioBatchRunService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiScenarioBatchRunService.java index 4398debf15..b2adc89321 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiScenarioBatchRunService.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiScenarioBatchRunService.java @@ -200,8 +200,7 @@ public class TestPlanApiScenarioBatchRunService { ExecutionQueue collectionQueue = apiExecutionQueueService.getQueue(collectionQueueId); if (collectionQueue == null) { // 失败停止,或者执行完成,更新任务状态 - apiBatchRunBaseService.updateTaskStatus(collectionQueueId); - apiBatchRunBaseService.removeRunningTaskCache(collectionQueueId); + apiBatchRunBaseService.updateTaskCompletedStatus(collectionQueueId); return; } String userId = collectionQueue.getUserId(); diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanExecuteService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanExecuteService.java index 3868636753..543f079fc6 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanExecuteService.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanExecuteService.java @@ -687,8 +687,7 @@ public class TestPlanExecuteService { TestPlanReport testPlanReport = testPlanReportMapper.selectByPrimaryKey(reportId); if (StringUtils.equals(testPlanReport.getParentId(), reportId) && StringUtils.isNotBlank(taskId)) { // 执行完成,更新任务状态 - apiBatchRunBaseService.updateTaskStatus(taskId); - apiBatchRunBaseService.removeRunningTaskCache(taskId); + apiBatchRunBaseService.updateTaskCompletedStatus(taskId); } testPlanExecuteSupportService.summaryTestPlanReport(reportId, isGroupReport, isStop); }