From fa013cfe978fd0bdc642cffda04853bb422f9f2e Mon Sep 17 00:00:00 2001 From: AgAngle <1323481023@qq.com> Date: Fri, 15 Nov 2024 22:33:13 +0800 Subject: [PATCH] =?UTF-8?q?feat(=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=95=B4=E4=BD=93=E6=89=A7?= =?UTF-8?q?=E8=A1=8C=EF=BC=8C=E9=87=8D=E8=B7=91=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --task=1016918 --user=陈建星 失败重跑 https://www.tapd.cn/55049933/s/1609836 --- .../metersphere/system/domain/ExecTask.java | 16 +- .../system/domain/ExecTaskExample.java | 320 +++++++++++------- .../system/domain/ExecTaskItem.java | 6 +- .../system/domain/ExecTaskItemExample.java | 60 ++++ .../system/mapper/ExecTaskItemMapper.xml | 35 +- .../system/mapper/ExecTaskMapper.xml | 131 ++++--- .../migration/3.5.0/ddl/V3.5.0_2__ga_ddl.sql | 4 + .../sdk/dto/api/task/GetRunScriptRequest.java | 2 +- .../sdk/dto/api/task/TaskInfo.java | 2 +- .../sdk/dto/queue/ExecutionQueue.java | 4 + .../sdk/dto/queue/TestPlanExecutionQueue.java | 5 +- .../api/service/ApiBatchRunBaseService.java | 4 +- .../api/service/ApiCommonService.java | 13 + .../service/rerun/ApiCaseRerunService.java | 10 +- .../rerun/ApiScenarioRerunService.java | 8 +- .../invoker/TaskRerunServiceInvoker.java | 8 +- .../system/mapper/ExtExecTaskItemMapper.java | 4 +- .../system/mapper/ExtExecTaskItemMapper.xml | 11 +- .../system/service/BaseTaskHubService.java | 10 +- .../system/service/TaskRerunService.java | 8 +- .../plan/mapper/ExtTestPlanReportMapper.java | 2 + .../plan/mapper/ExtTestPlanReportMapper.xml | 4 + .../PlanRunTestPlanApiCaseService.java | 12 +- .../PlanRunTestPlanApiScenarioService.java | 13 +- .../TestPlanApiCaseBatchRunService.java | 7 +- .../TestPlanApiScenarioBatchRunService.java | 4 +- .../plan/service/TestPlanExecuteService.java | 141 +++++++- .../plan/service/TestPlanReportService.java | 2 - .../rerun/TestPlanApiCaseRerunService.java | 9 +- .../TestPlanApiScenarioRerunService.java | 11 +- .../rerun/TestPlanGroupRerunService.java | 30 ++ .../service/rerun/TestPlanRerunService.java | 30 ++ 32 files changed, 643 insertions(+), 283 deletions(-) create mode 100644 backend/services/test-plan/src/main/java/io/metersphere/plan/service/rerun/TestPlanGroupRerunService.java create mode 100644 backend/services/test-plan/src/main/java/io/metersphere/plan/service/rerun/TestPlanRerunService.java diff --git a/backend/framework/domain/src/main/java/io/metersphere/system/domain/ExecTask.java b/backend/framework/domain/src/main/java/io/metersphere/system/domain/ExecTask.java index 917a2a4670..94e0908d45 100644 --- a/backend/framework/domain/src/main/java/io/metersphere/system/domain/ExecTask.java +++ b/backend/framework/domain/src/main/java/io/metersphere/system/domain/ExecTask.java @@ -1,11 +1,8 @@ package io.metersphere.system.domain; -import io.metersphere.validation.groups.Created; -import io.metersphere.validation.groups.Updated; +import io.metersphere.validation.groups.*; import io.swagger.v3.oas.annotations.media.Schema; -import jakarta.validation.constraints.NotBlank; -import jakarta.validation.constraints.NotNull; -import jakarta.validation.constraints.Size; +import jakarta.validation.constraints.*; import java.io.Serializable; import java.util.ArrayList; import java.util.Arrays; @@ -80,6 +77,10 @@ public class ExecTask implements Serializable { @NotNull(message = "{exec_task.deleted.not_blank}", groups = {Created.class}) private Boolean deleted; + @Schema(description = "是否是并行执行", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull(message = "{exec_task.parallel.not_blank}", groups = {Created.class}) + private Boolean parallel; + private static final long serialVersionUID = 1L; public enum Column { @@ -94,12 +95,13 @@ public class ExecTask implements Serializable { triggerMode("trigger_mode", "triggerMode", "VARCHAR", false), projectId("project_id", "projectId", "VARCHAR", false), organizationId("organization_id", "organizationId", "VARCHAR", false), + integrated("integrated", "integrated", "BIT", false), createTime("create_time", "createTime", "BIGINT", false), createUser("create_user", "createUser", "VARCHAR", false), startTime("start_time", "startTime", "BIGINT", false), endTime("end_time", "endTime", "BIGINT", false), - integrated("integrated", "integrated", "BIT", false), - deleted("deleted", "deleted", "BIT", false); + deleted("deleted", "deleted", "BIT", false), + parallel("parallel", "parallel", "BIT", false); private static final String BEGINNING_DELIMITER = "`"; diff --git a/backend/framework/domain/src/main/java/io/metersphere/system/domain/ExecTaskExample.java b/backend/framework/domain/src/main/java/io/metersphere/system/domain/ExecTaskExample.java index 15825a1d33..62e2900a72 100644 --- a/backend/framework/domain/src/main/java/io/metersphere/system/domain/ExecTaskExample.java +++ b/backend/framework/domain/src/main/java/io/metersphere/system/domain/ExecTaskExample.java @@ -574,6 +574,76 @@ public class ExecTaskExample { return (Criteria) this; } + public Criteria andResourceIdIsNull() { + addCriterion("resource_id is null"); + return (Criteria) this; + } + + public Criteria andResourceIdIsNotNull() { + addCriterion("resource_id is not null"); + return (Criteria) this; + } + + public Criteria andResourceIdEqualTo(String value) { + addCriterion("resource_id =", value, "resourceId"); + return (Criteria) this; + } + + public Criteria andResourceIdNotEqualTo(String value) { + addCriterion("resource_id <>", value, "resourceId"); + return (Criteria) this; + } + + public Criteria andResourceIdGreaterThan(String value) { + addCriterion("resource_id >", value, "resourceId"); + return (Criteria) this; + } + + public Criteria andResourceIdGreaterThanOrEqualTo(String value) { + addCriterion("resource_id >=", value, "resourceId"); + return (Criteria) this; + } + + public Criteria andResourceIdLessThan(String value) { + addCriterion("resource_id <", value, "resourceId"); + return (Criteria) this; + } + + public Criteria andResourceIdLessThanOrEqualTo(String value) { + addCriterion("resource_id <=", value, "resourceId"); + return (Criteria) this; + } + + public Criteria andResourceIdLike(String value) { + addCriterion("resource_id like", value, "resourceId"); + return (Criteria) this; + } + + public Criteria andResourceIdNotLike(String value) { + addCriterion("resource_id not like", value, "resourceId"); + return (Criteria) this; + } + + public Criteria andResourceIdIn(List values) { + addCriterion("resource_id in", values, "resourceId"); + return (Criteria) this; + } + + public Criteria andResourceIdNotIn(List values) { + addCriterion("resource_id not in", values, "resourceId"); + return (Criteria) this; + } + + public Criteria andResourceIdBetween(String value1, String value2) { + addCriterion("resource_id between", value1, value2, "resourceId"); + return (Criteria) this; + } + + public Criteria andResourceIdNotBetween(String value1, String value2) { + addCriterion("resource_id not between", value1, value2, "resourceId"); + return (Criteria) this; + } + public Criteria andTriggerModeIsNull() { addCriterion("trigger_mode is null"); return (Criteria) this; @@ -784,6 +854,66 @@ public class ExecTaskExample { return (Criteria) this; } + public Criteria andIntegratedIsNull() { + addCriterion("integrated is null"); + return (Criteria) this; + } + + public Criteria andIntegratedIsNotNull() { + addCriterion("integrated is not null"); + return (Criteria) this; + } + + public Criteria andIntegratedEqualTo(Boolean value) { + addCriterion("integrated =", value, "integrated"); + return (Criteria) this; + } + + public Criteria andIntegratedNotEqualTo(Boolean value) { + addCriterion("integrated <>", value, "integrated"); + return (Criteria) this; + } + + public Criteria andIntegratedGreaterThan(Boolean value) { + addCriterion("integrated >", value, "integrated"); + return (Criteria) this; + } + + public Criteria andIntegratedGreaterThanOrEqualTo(Boolean value) { + addCriterion("integrated >=", value, "integrated"); + return (Criteria) this; + } + + public Criteria andIntegratedLessThan(Boolean value) { + addCriterion("integrated <", value, "integrated"); + return (Criteria) this; + } + + public Criteria andIntegratedLessThanOrEqualTo(Boolean value) { + addCriterion("integrated <=", value, "integrated"); + return (Criteria) this; + } + + public Criteria andIntegratedIn(List values) { + addCriterion("integrated in", values, "integrated"); + return (Criteria) this; + } + + public Criteria andIntegratedNotIn(List values) { + addCriterion("integrated not in", values, "integrated"); + return (Criteria) this; + } + + public Criteria andIntegratedBetween(Boolean value1, Boolean value2) { + addCriterion("integrated between", value1, value2, "integrated"); + return (Criteria) this; + } + + public Criteria andIntegratedNotBetween(Boolean value1, Boolean value2) { + addCriterion("integrated not between", value1, value2, "integrated"); + return (Criteria) this; + } + public Criteria andCreateTimeIsNull() { addCriterion("create_time is null"); return (Criteria) this; @@ -1034,136 +1164,6 @@ public class ExecTaskExample { return (Criteria) this; } - public Criteria andIntegratedIsNull() { - addCriterion("integrated is null"); - return (Criteria) this; - } - - public Criteria andIntegratedIsNotNull() { - addCriterion("integrated is not null"); - return (Criteria) this; - } - - public Criteria andIntegratedEqualTo(Boolean value) { - addCriterion("integrated =", value, "integrated"); - return (Criteria) this; - } - - public Criteria andIntegratedNotEqualTo(Boolean value) { - addCriterion("integrated <>", value, "integrated"); - return (Criteria) this; - } - - public Criteria andIntegratedGreaterThan(Boolean value) { - addCriterion("integrated >", value, "integrated"); - return (Criteria) this; - } - - public Criteria andIntegratedGreaterThanOrEqualTo(Boolean value) { - addCriterion("integrated >=", value, "integrated"); - return (Criteria) this; - } - - public Criteria andIntegratedLessThan(Boolean value) { - addCriterion("integrated <", value, "integrated"); - return (Criteria) this; - } - - public Criteria andIntegratedLessThanOrEqualTo(Boolean value) { - addCriterion("integrated <=", value, "integrated"); - return (Criteria) this; - } - - public Criteria andIntegratedIn(List values) { - addCriterion("integrated in", values, "integrated"); - return (Criteria) this; - } - - public Criteria andIntegratedNotIn(List values) { - addCriterion("integrated not in", values, "integrated"); - return (Criteria) this; - } - - public Criteria andIntegratedBetween(Boolean value1, Boolean value2) { - addCriterion("integrated between", value1, value2, "integrated"); - return (Criteria) this; - } - - public Criteria andIntegratedNotBetween(Boolean value1, Boolean value2) { - addCriterion("integrated not between", value1, value2, "integrated"); - return (Criteria) this; - } - - public Criteria andResourceIdIsNull() { - addCriterion("resource_id is null"); - return (Criteria) this; - } - - public Criteria andResourceIdIsNotNull() { - addCriterion("resource_id is not null"); - return (Criteria) this; - } - - public Criteria andResourceIdEqualTo(String value) { - addCriterion("resource_id =", value, "resourceId"); - return (Criteria) this; - } - - public Criteria andResourceIdNotEqualTo(String value) { - addCriterion("resource_id <>", value, "resourceId"); - return (Criteria) this; - } - - public Criteria andResourceIdGreaterThan(String value) { - addCriterion("resource_id >", value, "resourceId"); - return (Criteria) this; - } - - public Criteria andResourceIdGreaterThanOrEqualTo(String value) { - addCriterion("resource_id >=", value, "resourceId"); - return (Criteria) this; - } - - public Criteria andResourceIdLessThan(String value) { - addCriterion("resource_id <", value, "resourceId"); - return (Criteria) this; - } - - public Criteria andResourceIdLessThanOrEqualTo(String value) { - addCriterion("resource_id <=", value, "resourceId"); - return (Criteria) this; - } - - public Criteria andResourceIdLike(String value) { - addCriterion("resource_id like", value, "resourceId"); - return (Criteria) this; - } - - public Criteria andResourceIdNotLike(String value) { - addCriterion("resource_id not like", value, "resourceId"); - return (Criteria) this; - } - - public Criteria andResourceIdIn(List values) { - addCriterion("resource_id in", values, "resourceId"); - return (Criteria) this; - } - - public Criteria andResourceIdNotIn(List values) { - addCriterion("resource_id not in", values, "resourceId"); - return (Criteria) this; - } - - public Criteria andResourceIdBetween(String value1, String value2) { - addCriterion("resource_id between", value1, value2, "resourceId"); - return (Criteria) this; - } - - public Criteria andResourceIdNotBetween(String value1, String value2) { - addCriterion("resource_id not between", value1, value2, "resourceId"); - return (Criteria) this; - } - public Criteria andDeletedIsNull() { addCriterion("deleted is null"); return (Criteria) this; @@ -1223,6 +1223,66 @@ public class ExecTaskExample { addCriterion("deleted not between", value1, value2, "deleted"); return (Criteria) this; } + + public Criteria andParallelIsNull() { + addCriterion("parallel is null"); + return (Criteria) this; + } + + public Criteria andParallelIsNotNull() { + addCriterion("parallel is not null"); + return (Criteria) this; + } + + public Criteria andParallelEqualTo(Boolean value) { + addCriterion("parallel =", value, "parallel"); + return (Criteria) this; + } + + public Criteria andParallelNotEqualTo(Boolean value) { + addCriterion("parallel <>", value, "parallel"); + return (Criteria) this; + } + + public Criteria andParallelGreaterThan(Boolean value) { + addCriterion("parallel >", value, "parallel"); + return (Criteria) this; + } + + public Criteria andParallelGreaterThanOrEqualTo(Boolean value) { + addCriterion("parallel >=", value, "parallel"); + return (Criteria) this; + } + + public Criteria andParallelLessThan(Boolean value) { + addCriterion("parallel <", value, "parallel"); + return (Criteria) this; + } + + public Criteria andParallelLessThanOrEqualTo(Boolean value) { + addCriterion("parallel <=", value, "parallel"); + return (Criteria) this; + } + + public Criteria andParallelIn(List values) { + addCriterion("parallel in", values, "parallel"); + return (Criteria) this; + } + + public Criteria andParallelNotIn(List values) { + addCriterion("parallel not in", values, "parallel"); + return (Criteria) this; + } + + public Criteria andParallelBetween(Boolean value1, Boolean value2) { + addCriterion("parallel between", value1, value2, "parallel"); + return (Criteria) this; + } + + public Criteria andParallelNotBetween(Boolean value1, Boolean value2) { + addCriterion("parallel not between", value1, value2, "parallel"); + return (Criteria) this; + } } public static class Criteria extends GeneratedCriteria { diff --git a/backend/framework/domain/src/main/java/io/metersphere/system/domain/ExecTaskItem.java b/backend/framework/domain/src/main/java/io/metersphere/system/domain/ExecTaskItem.java index 50bdb432ba..a0cd973225 100644 --- a/backend/framework/domain/src/main/java/io/metersphere/system/domain/ExecTaskItem.java +++ b/backend/framework/domain/src/main/java/io/metersphere/system/domain/ExecTaskItem.java @@ -91,6 +91,9 @@ public class ExecTaskItem implements Serializable { @Schema(description = "异常信息") private String errorMessage; + @Schema(description = "是否是重跑任务项") + private Boolean rerun; + private static final long serialVersionUID = 1L; public enum Column { @@ -113,7 +116,8 @@ public class ExecTaskItem implements Serializable { collectionId("collection_id", "collectionId", "VARCHAR", false), deleted("deleted", "deleted", "BIT", false), caseId("case_id", "caseId", "VARCHAR", false), - errorMessage("error_message", "errorMessage", "VARCHAR", false); + errorMessage("error_message", "errorMessage", "VARCHAR", false), + rerun("rerun", "rerun", "BIT", false); private static final String BEGINNING_DELIMITER = "`"; diff --git a/backend/framework/domain/src/main/java/io/metersphere/system/domain/ExecTaskItemExample.java b/backend/framework/domain/src/main/java/io/metersphere/system/domain/ExecTaskItemExample.java index c4e202f49a..d515851356 100644 --- a/backend/framework/domain/src/main/java/io/metersphere/system/domain/ExecTaskItemExample.java +++ b/backend/framework/domain/src/main/java/io/metersphere/system/domain/ExecTaskItemExample.java @@ -1473,6 +1473,66 @@ public class ExecTaskItemExample { addCriterion("error_message not between", value1, value2, "errorMessage"); return (Criteria) this; } + + public Criteria andRerunIsNull() { + addCriterion("rerun is null"); + return (Criteria) this; + } + + public Criteria andRerunIsNotNull() { + addCriterion("rerun is not null"); + return (Criteria) this; + } + + public Criteria andRerunEqualTo(Boolean value) { + addCriterion("rerun =", value, "rerun"); + return (Criteria) this; + } + + public Criteria andRerunNotEqualTo(Boolean value) { + addCriterion("rerun <>", value, "rerun"); + return (Criteria) this; + } + + public Criteria andRerunGreaterThan(Boolean value) { + addCriterion("rerun >", value, "rerun"); + return (Criteria) this; + } + + public Criteria andRerunGreaterThanOrEqualTo(Boolean value) { + addCriterion("rerun >=", value, "rerun"); + return (Criteria) this; + } + + public Criteria andRerunLessThan(Boolean value) { + addCriterion("rerun <", value, "rerun"); + return (Criteria) this; + } + + public Criteria andRerunLessThanOrEqualTo(Boolean value) { + addCriterion("rerun <=", value, "rerun"); + return (Criteria) this; + } + + public Criteria andRerunIn(List values) { + addCriterion("rerun in", values, "rerun"); + return (Criteria) this; + } + + public Criteria andRerunNotIn(List values) { + addCriterion("rerun not in", values, "rerun"); + return (Criteria) this; + } + + public Criteria andRerunBetween(Boolean value1, Boolean value2) { + addCriterion("rerun between", value1, value2, "rerun"); + return (Criteria) this; + } + + public Criteria andRerunNotBetween(Boolean value1, Boolean value2) { + addCriterion("rerun not between", value1, value2, "rerun"); + return (Criteria) this; + } } public static class Criteria extends GeneratedCriteria { diff --git a/backend/framework/domain/src/main/java/io/metersphere/system/mapper/ExecTaskItemMapper.xml b/backend/framework/domain/src/main/java/io/metersphere/system/mapper/ExecTaskItemMapper.xml index 01c0e78027..09262c8cbd 100644 --- a/backend/framework/domain/src/main/java/io/metersphere/system/mapper/ExecTaskItemMapper.xml +++ b/backend/framework/domain/src/main/java/io/metersphere/system/mapper/ExecTaskItemMapper.xml @@ -22,6 +22,7 @@ + @@ -84,7 +85,7 @@ id, task_id, resource_id, resource_name, task_origin, `status`, `result`, resource_pool_id, resource_pool_node, resource_type, project_id, organization_id, thread_id, start_time, - end_time, executor, collection_id, deleted, case_id, error_message + end_time, executor, collection_id, deleted, case_id, error_message, rerun @@ -328,6 +337,9 @@ error_message = #{record.errorMessage,jdbcType=VARCHAR}, + + rerun = #{record.rerun,jdbcType=BIT}, + @@ -354,7 +366,8 @@ collection_id = #{record.collectionId,jdbcType=VARCHAR}, deleted = #{record.deleted,jdbcType=BIT}, case_id = #{record.caseId,jdbcType=VARCHAR}, - error_message = #{record.errorMessage,jdbcType=VARCHAR} + error_message = #{record.errorMessage,jdbcType=VARCHAR}, + rerun = #{record.rerun,jdbcType=BIT} @@ -419,6 +432,9 @@ error_message = #{errorMessage,jdbcType=VARCHAR}, + + rerun = #{rerun,jdbcType=BIT}, + where id = #{id,jdbcType=VARCHAR} @@ -442,14 +458,15 @@ collection_id = #{collectionId,jdbcType=VARCHAR}, deleted = #{deleted,jdbcType=BIT}, case_id = #{caseId,jdbcType=VARCHAR}, - error_message = #{errorMessage,jdbcType=VARCHAR} + error_message = #{errorMessage,jdbcType=VARCHAR}, + rerun = #{rerun,jdbcType=BIT} where id = #{id,jdbcType=VARCHAR} insert into exec_task_item (id, task_id, resource_id, resource_name, task_origin, `status`, `result`, resource_pool_id, resource_pool_node, resource_type, project_id, organization_id, thread_id, start_time, - end_time, executor, collection_id, deleted, case_id, error_message) + end_time, executor, collection_id, deleted, case_id, error_message, rerun) values (#{item.id,jdbcType=VARCHAR}, #{item.taskId,jdbcType=VARCHAR}, #{item.resourceId,jdbcType=VARCHAR}, @@ -458,7 +475,8 @@ #{item.resourceType,jdbcType=VARCHAR}, #{item.projectId,jdbcType=VARCHAR}, #{item.organizationId,jdbcType=VARCHAR}, #{item.threadId,jdbcType=VARCHAR}, #{item.startTime,jdbcType=BIGINT}, #{item.endTime,jdbcType=BIGINT}, #{item.executor,jdbcType=VARCHAR}, #{item.collectionId,jdbcType=VARCHAR}, #{item.deleted,jdbcType=BIT}, - #{item.caseId,jdbcType=VARCHAR}, #{item.errorMessage,jdbcType=VARCHAR}) + #{item.caseId,jdbcType=VARCHAR}, #{item.errorMessage,jdbcType=VARCHAR}, #{item.rerun,jdbcType=BIT} + ) @@ -531,6 +549,9 @@ #{item.errorMessage,jdbcType=VARCHAR} + + #{item.rerun,jdbcType=BIT} + ) diff --git a/backend/framework/domain/src/main/java/io/metersphere/system/mapper/ExecTaskMapper.xml b/backend/framework/domain/src/main/java/io/metersphere/system/mapper/ExecTaskMapper.xml index 0d0096c172..864a155aad 100644 --- a/backend/framework/domain/src/main/java/io/metersphere/system/mapper/ExecTaskMapper.xml +++ b/backend/framework/domain/src/main/java/io/metersphere/system/mapper/ExecTaskMapper.xml @@ -9,16 +9,17 @@ + + - - + @@ -79,9 +80,9 @@ - id, num, task_name, `status`, case_count, `result`, task_type, trigger_mode, project_id, - organization_id, create_time, create_user, start_time, end_time, integrated, resource_id, - deleted + id, num, task_name, `status`, case_count, `result`, task_type, resource_id, trigger_mode, + project_id, organization_id, integrated, create_time, create_user, start_time, end_time, + deleted, parallel @@ -266,6 +273,9 @@ task_type = #{record.taskType,jdbcType=VARCHAR}, + + resource_id = #{record.resourceId,jdbcType=VARCHAR}, + trigger_mode = #{record.triggerMode,jdbcType=VARCHAR}, @@ -275,6 +285,9 @@ organization_id = #{record.organizationId,jdbcType=VARCHAR}, + + integrated = #{record.integrated,jdbcType=BIT}, + create_time = #{record.createTime,jdbcType=BIGINT}, @@ -287,15 +300,12 @@ end_time = #{record.endTime,jdbcType=BIGINT}, - - integrated = #{record.integrated,jdbcType=BIT}, - - - resource_id = #{record.resourceId,jdbcType=VARCHAR}, - deleted = #{record.deleted,jdbcType=BIT}, + + parallel = #{record.parallel,jdbcType=BIT}, + @@ -310,16 +320,17 @@ case_count = #{record.caseCount,jdbcType=BIGINT}, `result` = #{record.result,jdbcType=VARCHAR}, task_type = #{record.taskType,jdbcType=VARCHAR}, + resource_id = #{record.resourceId,jdbcType=VARCHAR}, trigger_mode = #{record.triggerMode,jdbcType=VARCHAR}, project_id = #{record.projectId,jdbcType=VARCHAR}, organization_id = #{record.organizationId,jdbcType=VARCHAR}, + integrated = #{record.integrated,jdbcType=BIT}, create_time = #{record.createTime,jdbcType=BIGINT}, create_user = #{record.createUser,jdbcType=VARCHAR}, start_time = #{record.startTime,jdbcType=BIGINT}, end_time = #{record.endTime,jdbcType=BIGINT}, - integrated = #{record.integrated,jdbcType=BIT}, - resource_id = #{record.resourceId,jdbcType=VARCHAR}, - deleted = #{record.deleted,jdbcType=BIT} + deleted = #{record.deleted,jdbcType=BIT}, + parallel = #{record.parallel,jdbcType=BIT} @@ -345,6 +356,9 @@ task_type = #{taskType,jdbcType=VARCHAR}, + + resource_id = #{resourceId,jdbcType=VARCHAR}, + trigger_mode = #{triggerMode,jdbcType=VARCHAR}, @@ -354,6 +368,9 @@ organization_id = #{organizationId,jdbcType=VARCHAR}, + + integrated = #{integrated,jdbcType=BIT}, + create_time = #{createTime,jdbcType=BIGINT}, @@ -366,15 +383,12 @@ end_time = #{endTime,jdbcType=BIGINT}, - - integrated = #{integrated,jdbcType=BIT}, - - - resource_id = #{resourceId,jdbcType=VARCHAR}, - deleted = #{deleted,jdbcType=BIT}, + + parallel = #{parallel,jdbcType=BIT}, + where id = #{id,jdbcType=VARCHAR} @@ -386,31 +400,33 @@ case_count = #{caseCount,jdbcType=BIGINT}, `result` = #{result,jdbcType=VARCHAR}, task_type = #{taskType,jdbcType=VARCHAR}, + resource_id = #{resourceId,jdbcType=VARCHAR}, trigger_mode = #{triggerMode,jdbcType=VARCHAR}, project_id = #{projectId,jdbcType=VARCHAR}, organization_id = #{organizationId,jdbcType=VARCHAR}, + integrated = #{integrated,jdbcType=BIT}, create_time = #{createTime,jdbcType=BIGINT}, create_user = #{createUser,jdbcType=VARCHAR}, start_time = #{startTime,jdbcType=BIGINT}, end_time = #{endTime,jdbcType=BIGINT}, - integrated = #{integrated,jdbcType=BIT}, - resource_id = #{resourceId,jdbcType=VARCHAR}, - deleted = #{deleted,jdbcType=BIT} + deleted = #{deleted,jdbcType=BIT}, + parallel = #{parallel,jdbcType=BIT} where id = #{id,jdbcType=VARCHAR} insert into exec_task - (id, num, task_name, `status`, case_count, `result`, task_type, trigger_mode, project_id, - organization_id, create_time, create_user, start_time, end_time, integrated, resource_id, - deleted) + (id, num, task_name, `status`, case_count, `result`, task_type, resource_id, trigger_mode, + project_id, organization_id, integrated, create_time, create_user, start_time, + end_time, deleted, parallel) values (#{item.id,jdbcType=VARCHAR}, #{item.num,jdbcType=BIGINT}, #{item.taskName,jdbcType=VARCHAR}, #{item.status,jdbcType=VARCHAR}, #{item.caseCount,jdbcType=BIGINT}, #{item.result,jdbcType=VARCHAR}, - #{item.taskType,jdbcType=VARCHAR}, #{item.triggerMode,jdbcType=VARCHAR}, #{item.projectId,jdbcType=VARCHAR}, - #{item.organizationId,jdbcType=VARCHAR}, #{item.createTime,jdbcType=BIGINT}, #{item.createUser,jdbcType=VARCHAR}, - #{item.startTime,jdbcType=BIGINT}, #{item.endTime,jdbcType=BIGINT}, #{item.integrated,jdbcType=BIT}, - #{item.resourceId,jdbcType=VARCHAR}, #{item.deleted,jdbcType=BIT}) + #{item.taskType,jdbcType=VARCHAR}, #{item.resourceId,jdbcType=VARCHAR}, #{item.triggerMode,jdbcType=VARCHAR}, + #{item.projectId,jdbcType=VARCHAR}, #{item.organizationId,jdbcType=VARCHAR}, #{item.integrated,jdbcType=BIT}, + #{item.createTime,jdbcType=BIGINT}, #{item.createUser,jdbcType=VARCHAR}, #{item.startTime,jdbcType=BIGINT}, + #{item.endTime,jdbcType=BIGINT}, #{item.deleted,jdbcType=BIT}, #{item.parallel,jdbcType=BIT} + ) @@ -444,6 +460,9 @@ #{item.taskType,jdbcType=VARCHAR} + + #{item.resourceId,jdbcType=VARCHAR} + #{item.triggerMode,jdbcType=VARCHAR} @@ -453,6 +472,9 @@ #{item.organizationId,jdbcType=VARCHAR} + + #{item.integrated,jdbcType=BIT} + #{item.createTime,jdbcType=BIGINT} @@ -465,15 +487,12 @@ #{item.endTime,jdbcType=BIGINT} - - #{item.integrated,jdbcType=BIT} - - - #{item.resourceId,jdbcType=VARCHAR} - #{item.deleted,jdbcType=BIT} + + #{item.parallel,jdbcType=BIT} + ) diff --git a/backend/framework/domain/src/main/resources/migration/3.5.0/ddl/V3.5.0_2__ga_ddl.sql b/backend/framework/domain/src/main/resources/migration/3.5.0/ddl/V3.5.0_2__ga_ddl.sql index 3af7f78c8e..506cf933d4 100644 --- a/backend/framework/domain/src/main/resources/migration/3.5.0/ddl/V3.5.0_2__ga_ddl.sql +++ b/backend/framework/domain/src/main/resources/migration/3.5.0/ddl/V3.5.0_2__ga_ddl.sql @@ -83,6 +83,10 @@ CREATE INDEX idx_case_id ON exec_task_item(case_id); ALTER TABLE exec_task_item ADD collection_id varchar(50) NULL COMMENT '测试集ID'; -- 任务项添加异常信息字段 ALTER TABLE exec_task_item ADD error_message varchar(50) NULL COMMENT '异常信息'; +-- 任务项添加重跑字段 +ALTER TABLE exec_task_item ADD rerun bit(1) DEFAULT 0 NULL COMMENT '是否是重跑任务项'; +-- 任务添加串并行字段 +ALTER TABLE exec_task ADD parallel bit(1) DEFAULT 1 NOT NULL COMMENT '是否是并行执行'; -- set innodb lock wait timeout to default SET SESSION innodb_lock_wait_timeout = DEFAULT; diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/task/GetRunScriptRequest.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/task/GetRunScriptRequest.java index cff813d45b..d09cea2e4c 100644 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/task/GetRunScriptRequest.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/task/GetRunScriptRequest.java @@ -71,5 +71,5 @@ public class GetRunScriptRequest implements Serializable { /** * 是否是任务失败重跑 */ - private Boolean rerun; + private Boolean rerun = false; } diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/task/TaskInfo.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/task/TaskInfo.java index 3693bba54c..5b6ba782dc 100644 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/task/TaskInfo.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/task/TaskInfo.java @@ -127,5 +127,5 @@ public class TaskInfo implements Serializable { /** * 是否是任务失败重跑 */ - private Boolean rerun; + private Boolean rerun = false; } diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/queue/ExecutionQueue.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/queue/ExecutionQueue.java index 3dc747a6a3..86c8f32c96 100644 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/queue/ExecutionQueue.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/queue/ExecutionQueue.java @@ -44,6 +44,10 @@ public class ExecutionQueue implements Serializable { * {@link io.metersphere.sdk.constants.ApiExecuteResourceType} */ private String resourceType; + /** + * 是否是重跑 + */ + private Boolean rerun = false; /** * 运行模式配置 diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/queue/TestPlanExecutionQueue.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/queue/TestPlanExecutionQueue.java index f8a1908a1b..1d716c21de 100644 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/queue/TestPlanExecutionQueue.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/queue/TestPlanExecutionQueue.java @@ -39,9 +39,11 @@ public class TestPlanExecutionQueue { private boolean isLastOne = false; // 是否执行完毕 private boolean executeFinish = false; + // 是否是重新执行 + private boolean rerun = false; public TestPlanExecutionQueue(long pos, String createUser, long createTime, String queueId, String queueType, String parentQueueId, String parentQueueType, String sourceID, String runMode, - String executionSource, String prepareReportId, String taskId) { + String executionSource, String prepareReportId, String taskId, boolean rerun) { this.pos = pos; this.createUser = createUser; this.createTime = createTime; @@ -54,5 +56,6 @@ public class TestPlanExecutionQueue { this.executionSource = executionSource; this.prepareReportId = prepareReportId; this.taskId = taskId; + this.rerun = rerun; } } 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 91fd2e97ab..2e980a0ebd 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 @@ -267,8 +267,8 @@ public class ApiBatchRunBaseService { } } - public List getExecTaskItemByTaskIdAndCollectionId(String taskId, String collectionId) { - List execTaskItems = extExecTaskItemMapper.selectExecInfoByTaskIdAndCollectionId(taskId, collectionId) + public List getExecTaskItemByTaskIdAndCollectionId(String taskId, String collectionId, boolean rerun) { + List execTaskItems = extExecTaskItemMapper.selectExecInfoByTaskIdAndCollectionId(taskId, collectionId, rerun) .stream().sorted(Comparator.comparing(ExecTaskItem::getId)).toList(); return execTaskItems; } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/ApiCommonService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/ApiCommonService.java index 4d3de3cd43..ee35346bae 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/ApiCommonService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/ApiCommonService.java @@ -35,12 +35,14 @@ import io.metersphere.sdk.constants.TaskItemErrorMessage; import io.metersphere.sdk.dto.api.task.GetRunScriptRequest; import io.metersphere.sdk.dto.api.task.TaskBatchRequestDTO; import io.metersphere.sdk.dto.api.task.TaskItem; +import io.metersphere.sdk.exception.MSException; import io.metersphere.sdk.util.BeanUtils; import io.metersphere.sdk.util.CommonBeanFactory; import io.metersphere.sdk.util.JSON; import io.metersphere.sdk.util.LogUtils; import io.metersphere.system.domain.ExecTask; import io.metersphere.system.domain.ExecTaskItem; +import io.metersphere.system.domain.ExecTaskItemExample; import io.metersphere.system.mapper.ExecTaskItemMapper; import io.metersphere.system.mapper.ExecTaskMapper; import io.metersphere.system.uid.IDGenerator; @@ -578,4 +580,15 @@ public class ApiCommonService { execTaskItem.setThreadId(request.getThreadId()); execTaskItemMapper.updateByPrimaryKeySelective(execTaskItem); } + + public ExecTaskItem getRerunTaskItem(String id) { + ExecTaskItemExample example = new ExecTaskItemExample(); + example.createCriteria().andTaskIdEqualTo(id).andRerunEqualTo(true); + List execTaskItems = execTaskItemMapper.selectByExample(example); + if (org.apache.commons.collections4.CollectionUtils.isEmpty(execTaskItems)) { + throw new MSException("No test cases to rerun"); + } + ExecTaskItem execTaskItem = execTaskItems.getFirst(); + return execTaskItem; + } } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/rerun/ApiCaseRerunService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/rerun/ApiCaseRerunService.java index 15d6c54ee3..e416c4eb2e 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/rerun/ApiCaseRerunService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/rerun/ApiCaseRerunService.java @@ -1,18 +1,16 @@ package io.metersphere.api.service.rerun; +import io.metersphere.api.service.ApiCommonService; import io.metersphere.api.service.definition.ApiTestCaseRunService; import io.metersphere.sdk.constants.ExecTaskType; import io.metersphere.system.domain.ExecTask; import io.metersphere.system.domain.ExecTaskItem; import io.metersphere.system.invoker.TaskRerunServiceInvoker; -import io.metersphere.system.mapper.ExecTaskItemMapper; import io.metersphere.system.service.TaskRerunService; import jakarta.annotation.Resource; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.List; - /** * @Author: jianxing * @CreateTime: 2024-02-06 20:47 @@ -23,15 +21,15 @@ public class ApiCaseRerunService implements TaskRerunService { @Resource private ApiTestCaseRunService apiTestCaseRunService; @Resource - private ExecTaskItemMapper execTaskItemMapper; + private ApiCommonService apiCommonService; public ApiCaseRerunService() { TaskRerunServiceInvoker.register(ExecTaskType.API_CASE, this); } @Override - public void rerun(ExecTask execTask, List taskItemIds, String userId) { - ExecTaskItem execTaskItem = execTaskItemMapper.selectByPrimaryKey(taskItemIds.getFirst()); + public void rerun(ExecTask execTask, String userId) { + ExecTaskItem execTaskItem = apiCommonService.getRerunTaskItem(execTask.getId()); apiTestCaseRunService.runRun(execTask, execTaskItem, userId); } } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/rerun/ApiScenarioRerunService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/rerun/ApiScenarioRerunService.java index 9a0d25f736..e738f59d06 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/rerun/ApiScenarioRerunService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/rerun/ApiScenarioRerunService.java @@ -1,11 +1,11 @@ package io.metersphere.api.service.rerun; +import io.metersphere.api.service.ApiCommonService; import io.metersphere.api.service.scenario.ApiScenarioRunService; import io.metersphere.sdk.constants.ExecTaskType; import io.metersphere.system.domain.ExecTask; import io.metersphere.system.domain.ExecTaskItem; import io.metersphere.system.invoker.TaskRerunServiceInvoker; -import io.metersphere.system.mapper.ExecTaskItemMapper; import io.metersphere.system.service.TaskRerunService; import jakarta.annotation.Resource; import org.springframework.stereotype.Service; @@ -23,15 +23,15 @@ public class ApiScenarioRerunService implements TaskRerunService { @Resource private ApiScenarioRunService apiScenarioRunService; @Resource - private ExecTaskItemMapper execTaskItemMapper; + private ApiCommonService apiCommonService; public ApiScenarioRerunService() { TaskRerunServiceInvoker.register(ExecTaskType.API_SCENARIO, this); } @Override - public void rerun(ExecTask execTask, List taskItemIds, String userId) { - ExecTaskItem execTaskItem = execTaskItemMapper.selectByPrimaryKey(taskItemIds.getFirst()); + public void rerun(ExecTask execTask, String userId) { + ExecTaskItem execTaskItem = apiCommonService.getRerunTaskItem(execTask.getId()); apiScenarioRunService.runRun(execTask, execTaskItem, userId); } } diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/invoker/TaskRerunServiceInvoker.java b/backend/services/system-setting/src/main/java/io/metersphere/system/invoker/TaskRerunServiceInvoker.java index 0f073824a7..adcd88ccef 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/invoker/TaskRerunServiceInvoker.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/invoker/TaskRerunServiceInvoker.java @@ -6,7 +6,6 @@ import io.metersphere.system.domain.ExecTask; import io.metersphere.system.service.TaskRerunService; import java.util.HashMap; -import java.util.List; import java.util.Map; /** @@ -29,7 +28,10 @@ public class TaskRerunServiceInvoker { return EnumValidator.validateEnum(ExecTaskType.class, execTaskType); } - public static void rerun(ExecTask execTask, List taskItemIds, String userId) { - getTaskRerunService(getExecTaskType(execTask.getTaskType())).rerun(execTask, taskItemIds, userId); + public static void rerun(ExecTask execTask, String userId) { + TaskRerunService taskRerunService = getTaskRerunService(getExecTaskType(execTask.getTaskType())); + if (taskRerunService != null) { + taskRerunService.rerun(execTask, userId); + } } } diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtExecTaskItemMapper.java b/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtExecTaskItemMapper.java index 5fdec3a782..9dd5f87a4e 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtExecTaskItemMapper.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtExecTaskItemMapper.java @@ -37,7 +37,7 @@ public interface ExtExecTaskItemMapper { List selectExecInfoByTaskIdAndResourceIds(@Param("taskId") String taskId, @Param("resourceIds") List resourceIds); - List selectExecInfoByTaskIdAndCollectionId(@Param("taskId") String taskId, @Param("collectionId") String collectionId); + List selectExecInfoByTaskIdAndCollectionId(@Param("taskId") String taskId, @Param("collectionId") String collectionId, @Param("rerun") boolean rerun); Boolean hasErrorItem(@Param("taskId") String taskId); @@ -64,8 +64,6 @@ public interface ExtExecTaskItemMapper { long getUnDeleteScenarioExecCount(@Param("projectId") String projectId, @Param("startTime") Long startTime, @Param("endTime") Long endTime, @Param("resourceTypes") List resourceTypes); - List selectRerunIds(@Param("taskId") String taskId); - void resetRerunTaskItem(@Param("taskId") String taskId, @Param("userId") String userId); void deleteRerunTaskItemReportRelation(@Param("taskId") String taskId); diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtExecTaskItemMapper.xml b/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtExecTaskItemMapper.xml index 058e2d9948..199d7c94e5 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtExecTaskItemMapper.xml +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtExecTaskItemMapper.xml @@ -33,6 +33,9 @@ SELECT id, resource_id FROM exec_task_item WHERE task_id = #{taskId} and collection_id = #{collectionId} + + and rerun = true + - - UPDATE exec_task_item SET `status` = 'PENDING', @@ -333,9 +332,9 @@ thread_id = null, start_time = null, end_time = null, - collection_id = null, error_message = null, - executor = #{userId} + executor = #{userId}, + rerun = true WHERE deleted = false and task_id = #{taskId} diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/service/BaseTaskHubService.java b/backend/services/system-setting/src/main/java/io/metersphere/system/service/BaseTaskHubService.java index 6b0ee467d1..1144c3b8c7 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/service/BaseTaskHubService.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/service/BaseTaskHubService.java @@ -528,6 +528,7 @@ public class BaseTaskHubService { List items = extExecTaskItemMapper.selectPoolNodeByIds(ids); return items.stream() + .filter(item -> StringUtils.isNotBlank(item.getResourcePoolNode())) .collect(Collectors.groupingBy(ExecTaskItem::getResourcePoolNode)) .entrySet() .stream() @@ -599,13 +600,6 @@ public class BaseTaskHubService { throw new MSException(Translator.get("no_permission_to_resource")); } - // 查询待执行的任务项 - List taskItemIds = extExecTaskItemMapper.selectRerunIds(execTask.getId()); - - if (CollectionUtils.isEmpty(taskItemIds)) { - return; - } - // 更新任务状态 execTask.setStatus(ExecStatus.RERUNNING.name()); execTask.setCreateUser(userId); @@ -626,7 +620,7 @@ public class BaseTaskHubService { // 更新任务项状态等 extExecTaskItemMapper.resetRerunTaskItem(execTask.getId(), userId); - TaskRerunServiceInvoker.rerun(execTask, taskItemIds, userId); + TaskRerunServiceInvoker.rerun(execTask, userId); } private void handleStopTaskAsync(List ids) { diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/service/TaskRerunService.java b/backend/services/system-setting/src/main/java/io/metersphere/system/service/TaskRerunService.java index 1e22a07c3a..6171a5147d 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/service/TaskRerunService.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/service/TaskRerunService.java @@ -1,16 +1,18 @@ package io.metersphere.system.service; import io.metersphere.system.domain.ExecTask; - -import java.util.List; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; /** * @Author: jianxing * @CreateTime: 2024-02-06 20:47 */ +@Service +@Transactional(rollbackFor = Exception.class) public interface TaskRerunService { /** * 任务重跑 */ - void rerun(ExecTask execTask, List taskItemIds, String userId); + void rerun(ExecTask execTask, String userId); } diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanReportMapper.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanReportMapper.java index 45d207334b..752f3b2959 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanReportMapper.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanReportMapper.java @@ -73,4 +73,6 @@ public interface ExtTestPlanReportMapper { void deleteGroupReport(@Param("id") String id); List getChildrenReport(@Param("reportId") String reportId); + + void resetRerunReport(@Param("reportId") String reportId); } diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanReportMapper.xml b/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanReportMapper.xml index a5ff02a7f7..caa4d9cf5b 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanReportMapper.xml +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanReportMapper.xml @@ -552,4 +552,8 @@ + + + update test_plan_report set exec_status = 'RUNNING', end_time = null where id = #{reportId} or parent_id = #{reportId} + \ No newline at end of file diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/PlanRunTestPlanApiCaseService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/PlanRunTestPlanApiCaseService.java index 5360788cab..f779c857ee 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/PlanRunTestPlanApiCaseService.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/PlanRunTestPlanApiCaseService.java @@ -76,7 +76,7 @@ public class PlanRunTestPlanApiCaseService { String collectionId = collection.getId(); String execQueueId = taskId + "_" + collectionId; - List execTaskItems = apiBatchRunBaseService.getExecTaskItemByTaskIdAndCollectionId(taskId, collectionId); + List execTaskItems = apiBatchRunBaseService.getExecTaskItemByTaskIdAndCollectionId(taskId, collectionId, testPlanExecutionQueue.isRerun()); if (CollectionUtils.isEmpty(execTaskItems)) { return true; } @@ -85,6 +85,7 @@ public class PlanRunTestPlanApiCaseService { ExecutionQueue queue = apiBatchRunBaseService.getExecutionQueue(runModeConfig, ApiExecuteResourceType.PLAN_RUN_API_CASE.name(), testPlanExecutionQueue.getTaskId(), userId); queue.setQueueId(execQueueId); + queue.setRerun(testPlanExecutionQueue.isRerun()); queue.setParentQueueId(testPlanExecutionQueue.getQueueId()); apiExecutionQueueService.insertQueue(queue); @@ -114,13 +115,15 @@ public class PlanRunTestPlanApiCaseService { TestPlan testPlan = testPlanMapper.selectByPrimaryKey(testPlanId); TaskBatchRequestDTO taskRequest = apiTestCaseBatchRunService.getTaskBatchRequestDTO(testPlan.getProjectId(), runModeConfig); - taskRequest.getTaskInfo().setTaskId(testPlanExecutionQueue.getTaskId()); + taskRequest.getTaskInfo().setTaskId(taskId); taskRequest.getTaskInfo().setParentQueueId(testPlanExecutionQueue.getQueueId()); taskRequest.getTaskInfo().setSetId(execSetId); + taskRequest.getTaskInfo().setRerun(testPlanExecutionQueue.isRerun()); taskRequest.getTaskInfo().setUserId(userId); taskRequest.getTaskInfo().setResourceType(ApiExecuteResourceType.PLAN_RUN_API_CASE.name()); - List execTaskItems = apiBatchRunBaseService.getExecTaskItemByTaskIdAndCollectionId(testPlanExecutionQueue.getTaskId(), collection.getId()); + List execTaskItems = apiBatchRunBaseService.getExecTaskItemByTaskIdAndCollectionId(testPlanExecutionQueue.getTaskId(), + collection.getId(), testPlanExecutionQueue.isRerun()); SubListUtils.dealForSubList(execTaskItems, ApiBatchRunBaseService.BATCH_TASK_ITEM_SIZE, subExecTaskItems -> { List taskItems = subExecTaskItems .stream() @@ -166,6 +169,7 @@ public class PlanRunTestPlanApiCaseService { taskRequest.getTaskInfo().setResourceType(ApiExecuteResourceType.PLAN_RUN_API_CASE.name()); taskRequest.getTaskInfo().setQueueId(queue.getQueueId()); taskRequest.getTaskInfo().setUserId(queue.getUserId()); + taskRequest.getTaskInfo().setRerun(queue.getRerun()); taskRequest.getTaskInfo().setParentQueueId(queue.getParentQueueId()); taskRequest.getTaskItem().setRequestCount(1L); taskRequest.getTaskItem().setId(queueDetail.getTaskItemId()); @@ -183,8 +187,6 @@ public class PlanRunTestPlanApiCaseService { ApiReport apiReport = apiTestCaseRunService.getApiReport(apiTestCase, request); apiReport.setEnvironmentId(apiBatchRunBaseService.getEnvId(request.getRunModeConfig(), testPlanReportApiCase.getEnvironmentId())); apiReport.setTestPlanCaseId(testPlanReportApiCase.getTestPlanApiCaseId()); - // 报告ID预生成 - apiReport.setId(testPlanReportApiCase.getApiCaseExecuteReportId()); // 标记是测试计划整体执行 apiReport.setPlan(true); apiReportService.insertApiReport(apiReport); diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/PlanRunTestPlanApiScenarioService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/PlanRunTestPlanApiScenarioService.java index 59de45380d..f899870801 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/PlanRunTestPlanApiScenarioService.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/PlanRunTestPlanApiScenarioService.java @@ -72,7 +72,7 @@ public class PlanRunTestPlanApiScenarioService { String collectionId = collection.getId(); String execQueueId = taskId + "_" + collectionId; - List execTaskItems = apiBatchRunBaseService.getExecTaskItemByTaskIdAndCollectionId(taskId, collectionId); + List execTaskItems = apiBatchRunBaseService.getExecTaskItemByTaskIdAndCollectionId(taskId, collectionId, testPlanExecutionQueue.isRerun()); if (CollectionUtils.isEmpty(execTaskItems)) { return true; } @@ -81,6 +81,7 @@ public class PlanRunTestPlanApiScenarioService { ExecutionQueue queue = apiBatchRunBaseService.getExecutionQueue(runModeConfig, ApiExecuteResourceType.PLAN_RUN_API_SCENARIO.name(), testPlanExecutionQueue.getTaskId(), userId); queue.setQueueId(execQueueId); + queue.setRerun(testPlanExecutionQueue.isRerun()); queue.setParentQueueId(testPlanExecutionQueue.getQueueId()); apiExecutionQueueService.insertQueue(queue); @@ -113,9 +114,11 @@ public class PlanRunTestPlanApiScenarioService { taskRequest.getTaskInfo().setParentQueueId(testPlanExecutionQueue.getQueueId()); taskRequest.getTaskInfo().setSetId(execSetId); taskRequest.getTaskInfo().setUserId(userId); + taskRequest.getTaskInfo().setRerun(testPlanExecutionQueue.isRerun()); taskRequest.getTaskInfo().setResourceType(ApiExecuteResourceType.PLAN_RUN_API_SCENARIO.name()); - List execTaskItems = apiBatchRunBaseService.getExecTaskItemByTaskIdAndCollectionId(testPlanExecutionQueue.getTaskId(), collection.getId()); + List execTaskItems = apiBatchRunBaseService.getExecTaskItemByTaskIdAndCollectionId(testPlanExecutionQueue.getTaskId(), + collection.getId(), testPlanExecutionQueue.isRerun()); SubListUtils.dealForSubList(execTaskItems, ApiBatchRunBaseService.BATCH_TASK_ITEM_SIZE, subExecTaskItems -> { List taskItems = subExecTaskItems .stream() @@ -141,16 +144,13 @@ public class PlanRunTestPlanApiScenarioService { // 初始化报告 ApiScenarioReport apiScenarioReport = apiScenarioRunService.getScenarioReport(apiScenario, request); apiScenarioReport.setName(testPlanReportApiScenario.getApiScenarioName() + "_" + DateUtils.getTimeString(System.currentTimeMillis())); - apiScenarioReport.setTestPlanScenarioId(testPlanReportApiScenario.getTestPlanApiScenarioId()); - // 报告预生成,方便停止测试计划时直接更新报告状态 - apiScenarioReport.setId(testPlanReportApiScenario.getApiScenarioExecuteReportId()); apiScenarioReport.setEnvironmentId(apiBatchRunBaseService.getEnvId(request.getRunModeConfig(), testPlanReportApiScenario.getEnvironmentId())); apiScenarioReport.setPlan(true); + apiScenarioReport.setTestPlanScenarioId(testPlanReportApiScenario.getTestPlanApiScenarioId()); apiScenarioReportService.insertApiScenarioReport(apiScenarioReport); return apiScenarioRunService.initApiScenarioReportDetail(request.getTaskItem().getId(), apiScenario.getId(), apiScenarioReport.getId()); } - /** * 执行串行的下一个任务 * @@ -176,6 +176,7 @@ public class PlanRunTestPlanApiScenarioService { taskRequest.getTaskInfo().setTaskId(queue.getTaskId()); taskRequest.getTaskInfo().setQueueId(queue.getQueueId()); taskRequest.getTaskInfo().setUserId(queue.getUserId()); + taskRequest.getTaskInfo().setRerun(queue.getRerun()); taskRequest.getTaskInfo().setParentQueueId(queue.getParentQueueId()); taskRequest.getTaskInfo().setResourceType(ApiExecuteResourceType.PLAN_RUN_API_SCENARIO.name()); 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 2277cd353f..6dfd71eb39 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 @@ -30,7 +30,6 @@ import io.metersphere.sdk.util.SubListUtils; import io.metersphere.sdk.util.Translator; import io.metersphere.system.domain.ExecTask; import io.metersphere.system.domain.ExecTaskItem; -import io.metersphere.system.mapper.ExtExecTaskItemMapper; import io.metersphere.system.service.BaseTaskHubService; import jakarta.annotation.Resource; import org.apache.commons.collections.CollectionUtils; @@ -74,8 +73,6 @@ public class TestPlanApiCaseBatchRunService { @Resource private BaseTaskHubService baseTaskHubService; @Resource - private ExtExecTaskItemMapper extExecTaskItemMapper; - @Resource private TestPlanService testPlanService; /** @@ -197,7 +194,7 @@ public class TestPlanApiCaseBatchRunService { // 初始化执行队列 ExecutionQueue queue = apiBatchRunBaseService.initExecutionQueue(taskId, taskId + '_' + collectionId, runModeConfig, ApiExecuteResourceType.TEST_PLAN_API_CASE.name(), parentQueueId, parentSetId, userId); - List execTaskItems = apiBatchRunBaseService.getExecTaskItemByTaskIdAndCollectionId(taskId, collectionId); + List execTaskItems = apiBatchRunBaseService.getExecTaskItemByTaskIdAndCollectionId(taskId, collectionId, false); apiBatchRunBaseService.initQueueDetail(queue, execTaskItems); @@ -232,7 +229,7 @@ public class TestPlanApiCaseBatchRunService { taskRequest.getTaskInfo().setParentSetId(parentSetId); } - List execTaskItems = apiBatchRunBaseService.getExecTaskItemByTaskIdAndCollectionId(taskId, collectionId); + List execTaskItems = apiBatchRunBaseService.getExecTaskItemByTaskIdAndCollectionId(taskId, collectionId, false); SubListUtils.dealForSubList(execTaskItems, ApiBatchRunBaseService.BATCH_TASK_ITEM_SIZE, subExecTaskItems -> { List taskItems = subExecTaskItems 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 0334db1080..6b908ee24d 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 @@ -205,7 +205,7 @@ public class TestPlanApiScenarioBatchRunService { // 初始化执行队列 ExecutionQueue queue = apiBatchRunBaseService.initExecutionQueue(taskId, taskId + '_' + collectionId, runModeConfig, ApiExecuteResourceType.TEST_PLAN_API_SCENARIO.name(), parentQueueId, parentSetId, userId); - List execTaskItems = apiBatchRunBaseService.getExecTaskItemByTaskIdAndCollectionId(taskId, collectionId); + List execTaskItems = apiBatchRunBaseService.getExecTaskItemByTaskIdAndCollectionId(taskId, collectionId, false); apiBatchRunBaseService.initQueueDetail(queue, execTaskItems); @@ -239,7 +239,7 @@ public class TestPlanApiScenarioBatchRunService { taskRequest.getTaskInfo().setParentSetId(parentSetId); } - List execTaskItems = apiBatchRunBaseService.getExecTaskItemByTaskIdAndCollectionId(taskId, collectionId); + List execTaskItems = apiBatchRunBaseService.getExecTaskItemByTaskIdAndCollectionId(taskId, collectionId, false); SubListUtils.dealForSubList(execTaskItems, ApiBatchRunBaseService.BATCH_TASK_ITEM_SIZE, subExecTaskItems -> { List taskItems = subExecTaskItems .stream() 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 29131fea2f..4dc8c0695b 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 @@ -2,6 +2,7 @@ package io.metersphere.plan.service; import com.esotericsoftware.minlog.Log; import io.metersphere.api.domain.ApiReportRelateTask; +import io.metersphere.api.domain.ApiReportRelateTaskExample; import io.metersphere.api.mapper.ApiReportRelateTaskMapper; import io.metersphere.api.service.ApiBatchRunBaseService; import io.metersphere.api.service.ApiCommonService; @@ -23,6 +24,7 @@ import io.metersphere.system.service.BaseTaskHubService; import io.metersphere.system.uid.IDGenerator; import jakarta.annotation.Resource; import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Propagation; @@ -32,6 +34,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.stream.Collectors; import static io.metersphere.plan.service.TestPlanExecuteSupportService.*; @@ -80,6 +83,8 @@ public class TestPlanExecuteService { private ApiBatchRunBaseService apiBatchRunBaseService; @Resource private ApiReportRelateTaskMapper apiReportRelateTaskMapper; + @Resource + private ExtTestPlanReportMapper extTestPlanReportMapper; // 停止测试计划的执行 public void stopTestPlanRunning(String testPlanReportId) { @@ -168,7 +173,8 @@ public class TestPlanExecuteService { request.getRunMode(), request.getExecutionSource(), reportId, - IDGenerator.nextStr() + IDGenerator.nextStr(), + false ); testPlanExecuteSupportService.setRedisForList( @@ -210,7 +216,8 @@ public class TestPlanExecuteService { runMode, TaskTriggerMode.BATCH.name(), IDGenerator.nextStr(), - IDGenerator.nextStr() + IDGenerator.nextStr(), + false ) ); } @@ -253,7 +260,7 @@ public class TestPlanExecuteService { extTestPlanApiScenarioMapper.countByPlanIds(childPlanIds); } // 初始化任务 - ExecTask execTask = initExecTask(executionQueue.getTaskId(), caseTotal, testPlan, project, executionQueue.getCreateUser(), executionQueue.getExecutionSource(), executionQueue.getPrepareReportId()); + ExecTask execTask = initExecTask(executionQueue, caseTotal, testPlan, project); // 预生成计划组报告 Map reportMap = testPlanReportService.genReportByExecution(executionQueue.getPrepareReportId(), execTask.getId(), genReportRequest, executionQueue.getCreateUser()); @@ -276,7 +283,8 @@ public class TestPlanExecuteService { executionQueue.getRunMode(), executionQueue.getExecutionSource(), reportMap.get(child.getId()), - executionQueue.getTaskId() + executionQueue.getTaskId(), + executionQueue.isRerun() ) ); } @@ -309,7 +317,7 @@ public class TestPlanExecuteService { Integer caseTotal = extTestPlanApiCaseMapper.countByPlanIds(List.of(testPlan.getId())) + extTestPlanApiScenarioMapper.countByPlanIds(List.of(testPlan.getId())); // 初始化任务 - ExecTask execTask = initExecTask(executionQueue.getTaskId(), caseTotal, testPlan, project, executionQueue.getCreateUser(), executionQueue.getExecutionSource(), executionQueue.getPrepareReportId()); + ExecTask execTask = initExecTask(executionQueue, caseTotal, testPlan, project); Map reportMap = testPlanReportService.genReportByExecution(executionQueue.getPrepareReportId(), execTask.getId(), genReportRequest, executionQueue.getCreateUser()); executionQueue.setPrepareReportId(reportMap.get(executionQueue.getSourceID())); @@ -319,21 +327,22 @@ public class TestPlanExecuteService { } } - private ExecTask initExecTask(String taskId, int caseSize, TestPlan testPlan, Project project, String userId, String triggerMode, String reportId) { - ExecTask execTask = apiCommonService.newExecTask(project.getId(), userId); - execTask.setId(taskId); + private ExecTask initExecTask(TestPlanExecutionQueue executionQueue, int caseSize, TestPlan testPlan, Project project) { + ExecTask execTask = apiCommonService.newExecTask(project.getId(), executionQueue.getCreateUser()); + execTask.setId(executionQueue.getTaskId()); execTask.setCaseCount(Long.valueOf(caseSize)); execTask.setTaskName(testPlan.getName()); execTask.setOrganizationId(project.getOrganizationId()); - execTask.setTriggerMode(triggerMode); + execTask.setTriggerMode(executionQueue.getExecutionSource()); + execTask.setParallel(StringUtils.equals(executionQueue.getRunMode(), ApiBatchRunMode.PARALLEL.name())); execTask.setTaskType(StringUtils.equalsIgnoreCase(testPlan.getType(), TestPlanConstants.TEST_PLAN_TYPE_PLAN) ? ExecTaskType.TEST_PLAN.name() : ExecTaskType.TEST_PLAN_GROUP.name()); execTask.setResourceId(testPlan.getId()); baseTaskHubService.insertExecTask(execTask); // 创建报告和任务的关联关系 ApiReportRelateTask apiReportRelateTask = new ApiReportRelateTask(); - apiReportRelateTask.setReportId(reportId); - apiReportRelateTask.setTaskResourceId(taskId); + apiReportRelateTask.setReportId(executionQueue.getPrepareReportId()); + apiReportRelateTask.setTaskResourceId(execTask.getId()); apiReportRelateTaskMapper.insertSelective(apiReportRelateTask); return execTask; } @@ -376,7 +385,8 @@ public class TestPlanExecuteService { runMode, executionQueue.getExecutionSource(), executionQueue.getPrepareReportId(), - executionQueue.getTaskId()) + executionQueue.getTaskId(), + executionQueue.isRerun()) ); } LogUtils.info("测试计划执行节点 --- 队列ID[{}],队列类型[{}],父队列ID[{}],父队列类型[{}],执行模式[{}]", queueId, queueType, executionQueue.getParentQueueId(), executionQueue.getParentQueueType(), runMode); @@ -401,6 +411,110 @@ public class TestPlanExecuteService { } } + public String testPlanOrGroupRerun(ExecTask execTask, String userId) { + String taskId = execTask.getId(); + ApiReportRelateTaskExample example = new ApiReportRelateTaskExample(); + example.createCriteria().andTaskResourceIdEqualTo(taskId); + List apiReportRelateTasks = apiReportRelateTaskMapper.selectByExample(example); + String reportId; + if (CollectionUtils.isNotEmpty(apiReportRelateTasks)) { + reportId = apiReportRelateTasks.getFirst().getReportId(); + } else { + // 报告被删除,生成虚拟ID + reportId = IDGenerator.nextStr(); + } + + String queueId = IDGenerator.nextStr(); + TestPlanExecutionQueue singleExecuteRootQueue = new TestPlanExecutionQueue( + 0, + userId, + System.currentTimeMillis(), + queueId, + QUEUE_PREFIX_TEST_PLAN_BATCH_EXECUTE, + null, + null, + execTask.getResourceId(), + BooleanUtils.isTrue(execTask.getParallel()) ? ApiBatchRunMode.PARALLEL.name() : ApiBatchRunMode.SERIAL.name(), + TaskTriggerMode.MANUAL.name(), + reportId, + taskId, + true + ); + + testPlanExecuteSupportService.setRedisForList( + testPlanExecuteSupportService.genQueueKey(queueId, QUEUE_PREFIX_TEST_PLAN_BATCH_EXECUTE), List.of(JSON.toJSONString(singleExecuteRootQueue))); + TestPlanExecutionQueue nextQueue = testPlanExecuteSupportService.getNextQueue(queueId, QUEUE_PREFIX_TEST_PLAN_BATCH_EXECUTE); + LogUtils.info("测试计划(组)重跑!计划报告[{}] , 资源ID[{}]", singleExecuteRootQueue.getPrepareReportId(), singleExecuteRootQueue.getSourceID()); + doTestPlanOrGroupRerun(nextQueue); + return reportId; + } + + private String doTestPlanOrGroupRerun(TestPlanExecutionQueue executionQueue) { + TestPlan testPlan = testPlanMapper.selectByPrimaryKey(executionQueue.getSourceID()); + if (testPlan == null || StringUtils.equalsIgnoreCase(testPlan.getStatus(), TestPlanConstants.TEST_PLAN_STATUS_ARCHIVED)) { + throw new MSException("test_plan.error"); + } + + String prepareReportId = executionQueue.getPrepareReportId(); + + // 更新计划组以及子计划的状态为 RUNNING + extTestPlanReportMapper.resetRerunReport(prepareReportId); + + if (StringUtils.equalsIgnoreCase(testPlan.getType(), TestPlanConstants.TEST_PLAN_TYPE_GROUP)) { + List children = testPlanService.selectNotArchivedChildren(testPlan.getId()); + long pos = 0; + List childrenQueue = new ArrayList<>(); + String queueType = QUEUE_PREFIX_TEST_PLAN_GROUP_EXECUTE; + String queueId = prepareReportId; + + TestPlanReportExample example = new TestPlanReportExample(); + example.createCriteria().andParentIdEqualTo(prepareReportId); + Map planReportMap = testPlanReportMapper.selectByExample(example).stream(). + collect(Collectors.toMap(TestPlanReport::getTestPlanId, TestPlanReport::getId)); + + for (TestPlan child : children) { + childrenQueue.add( + new TestPlanExecutionQueue( + pos++, + executionQueue.getCreateUser(), + System.currentTimeMillis(), + queueId, + queueType, + executionQueue.getQueueId(), + executionQueue.getQueueType(), + child.getId(), + executionQueue.getRunMode(), + executionQueue.getExecutionSource(), + planReportMap.get(child.getId()) == null ? IDGenerator.nextStr() : planReportMap.get(child.getId()), + executionQueue.getTaskId(), + executionQueue.isRerun() + ) + ); + } + + LogUtils.info("计划组重跑 --- 队列ID[{}],队列类型[{}]", queueId, queueType); + if (CollectionUtils.isEmpty(childrenQueue)) { + //本次的测试计划组执行完成 + this.testPlanGroupQueueFinish(queueId, queueType); + } else { + testPlanExecuteSupportService.setRedisForList(testPlanExecuteSupportService.genQueueKey(queueId, queueType), childrenQueue.stream().map(JSON::toJSONString).toList()); + + if (StringUtils.equalsIgnoreCase(executionQueue.getRunMode(), ApiBatchRunMode.SERIAL.name())) { + //串行 + TestPlanExecutionQueue nextQueue = testPlanExecuteSupportService.getNextQueue(queueId, queueType); + executeTestPlan(nextQueue); + } else { + //并行 + childrenQueue.forEach(childQueue -> executeTestPlan(childQueue)); + } + } + + } else { + this.executeTestPlan(executionQueue); + } + return prepareReportId; + } + //执行测试集 -- 回调:collectionExecuteQueueFinish private void executeByTestPlanCollection(TestPlanExecutionQueue executionQueue) { TestPlanCollection parentCollection = testPlanCollectionMapper.selectByPrimaryKey(executionQueue.getSourceID()); @@ -429,7 +543,8 @@ public class TestPlanExecuteService { runMode, executionQueue.getExecutionSource(), executionQueue.getPrepareReportId(), - executionQueue.getTaskId()) {{ + executionQueue.getTaskId(), + executionQueue.isRerun()) {{ this.setTestPlanCollectionJson(JSON.toJSONString(collection)); }} ); diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanReportService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanReportService.java index 4ae7543775..d0b07d9456 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanReportService.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanReportService.java @@ -550,7 +550,6 @@ public class TestPlanReportService { // 接口执行时才更新结果 reportApiCase.setApiCaseExecuteResult(null); reportApiCase.setApiCaseExecuteUser(null); - reportApiCase.setApiCaseExecuteReportId(IDGenerator.nextStr()); } reportApiCase.setApiCaseBugCount(bugCountMap.containsKey(reportApiCase.getTestPlanApiCaseId()) ? bugCountMap.get(reportApiCase.getTestPlanApiCaseId()) : 0); } @@ -593,7 +592,6 @@ public class TestPlanReportService { // 接口执行时才更新结果 reportApiScenario.setApiScenarioExecuteResult(null); reportApiScenario.setApiScenarioExecuteUser(null); - reportApiScenario.setApiScenarioExecuteReportId(IDGenerator.nextStr()); } reportApiScenario.setApiScenarioBugCount(bugCountMap.containsKey(reportApiScenario.getTestPlanApiScenarioId()) ? bugCountMap.get(reportApiScenario.getTestPlanApiScenarioId()) : 0); } diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/rerun/TestPlanApiCaseRerunService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/rerun/TestPlanApiCaseRerunService.java index 9dff766217..eaa135561b 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/rerun/TestPlanApiCaseRerunService.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/rerun/TestPlanApiCaseRerunService.java @@ -1,17 +1,16 @@ package io.metersphere.plan.service.rerun; +import io.metersphere.api.service.ApiCommonService; import io.metersphere.plan.service.TestPlanApiCaseService; import io.metersphere.sdk.constants.ExecTaskType; import io.metersphere.system.domain.ExecTask; import io.metersphere.system.domain.ExecTaskItem; import io.metersphere.system.invoker.TaskRerunServiceInvoker; -import io.metersphere.system.mapper.ExecTaskItemMapper; import io.metersphere.system.service.TaskRerunService; import jakarta.annotation.Resource; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.List; /** * @Author: jianxing @@ -23,15 +22,15 @@ public class TestPlanApiCaseRerunService implements TaskRerunService { @Resource private TestPlanApiCaseService testPlanApiCaseService; @Resource - private ExecTaskItemMapper execTaskItemMapper; + private ApiCommonService apiCommonService; public TestPlanApiCaseRerunService() { TaskRerunServiceInvoker.register(ExecTaskType.TEST_PLAN_API_CASE, this); } @Override - public void rerun(ExecTask execTask, List taskItemIds, String userId) { - ExecTaskItem execTaskItem = execTaskItemMapper.selectByPrimaryKey(taskItemIds.getFirst()); + public void rerun(ExecTask execTask, String userId) { + ExecTaskItem execTaskItem = apiCommonService.getRerunTaskItem(execTask.getId()); testPlanApiCaseService.runRun(execTask, execTaskItem, userId); } } diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/rerun/TestPlanApiScenarioRerunService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/rerun/TestPlanApiScenarioRerunService.java index 42494d3041..7739aa90ef 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/rerun/TestPlanApiScenarioRerunService.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/rerun/TestPlanApiScenarioRerunService.java @@ -1,18 +1,16 @@ package io.metersphere.plan.service.rerun; +import io.metersphere.api.service.ApiCommonService; import io.metersphere.plan.service.TestPlanApiScenarioService; import io.metersphere.sdk.constants.ExecTaskType; import io.metersphere.system.domain.ExecTask; import io.metersphere.system.domain.ExecTaskItem; import io.metersphere.system.invoker.TaskRerunServiceInvoker; -import io.metersphere.system.mapper.ExecTaskItemMapper; import io.metersphere.system.service.TaskRerunService; import jakarta.annotation.Resource; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.List; - /** * @Author: jianxing * @CreateTime: 2024-02-06 20:47 @@ -23,15 +21,16 @@ public class TestPlanApiScenarioRerunService implements TaskRerunService { @Resource private TestPlanApiScenarioService testPlanApiScenarioService; @Resource - private ExecTaskItemMapper execTaskItemMapper; + private ApiCommonService apiCommonService; + public TestPlanApiScenarioRerunService() { TaskRerunServiceInvoker.register(ExecTaskType.TEST_PLAN_API_SCENARIO, this); } @Override - public void rerun(ExecTask execTask, List taskItemIds, String userId) { - ExecTaskItem execTaskItem = execTaskItemMapper.selectByPrimaryKey(taskItemIds.getFirst()); + public void rerun(ExecTask execTask, String userId) { + ExecTaskItem execTaskItem = apiCommonService.getRerunTaskItem(execTask.getId()); testPlanApiScenarioService.runRun(execTask, execTaskItem, userId); } } diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/rerun/TestPlanGroupRerunService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/rerun/TestPlanGroupRerunService.java new file mode 100644 index 0000000000..d85af97293 --- /dev/null +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/rerun/TestPlanGroupRerunService.java @@ -0,0 +1,30 @@ +package io.metersphere.plan.service.rerun; + +import io.metersphere.plan.service.TestPlanExecuteService; +import io.metersphere.sdk.constants.ExecTaskType; +import io.metersphere.system.domain.ExecTask; +import io.metersphere.system.invoker.TaskRerunServiceInvoker; +import io.metersphere.system.service.TaskRerunService; +import jakarta.annotation.Resource; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +/** + * @Author: jianxing + * @CreateTime: 2024-02-06 20:47 + */ +@Service +@Transactional(rollbackFor = Exception.class) +public class TestPlanGroupRerunService implements TaskRerunService { + @Resource + private TestPlanExecuteService testPlanExecuteService; + + public TestPlanGroupRerunService() { + TaskRerunServiceInvoker.register(ExecTaskType.TEST_PLAN_GROUP, this); + } + + @Override + public void rerun(ExecTask execTask, String userId) { + Thread.startVirtualThread(() -> testPlanExecuteService.testPlanOrGroupRerun(execTask, userId)); + } +} diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/rerun/TestPlanRerunService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/rerun/TestPlanRerunService.java new file mode 100644 index 0000000000..f448d04b8f --- /dev/null +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/rerun/TestPlanRerunService.java @@ -0,0 +1,30 @@ +package io.metersphere.plan.service.rerun; + +import io.metersphere.plan.service.TestPlanExecuteService; +import io.metersphere.sdk.constants.ExecTaskType; +import io.metersphere.system.domain.ExecTask; +import io.metersphere.system.invoker.TaskRerunServiceInvoker; +import io.metersphere.system.service.TaskRerunService; +import jakarta.annotation.Resource; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +/** + * @Author: jianxing + * @CreateTime: 2024-02-06 20:47 + */ +@Service +@Transactional(rollbackFor = Exception.class) +public class TestPlanRerunService implements TaskRerunService { + @Resource + private TestPlanExecuteService testPlanExecuteService; + + public TestPlanRerunService() { + TaskRerunServiceInvoker.register(ExecTaskType.TEST_PLAN, this); + } + + @Override + public void rerun(ExecTask execTask, String userId) { + Thread.startVirtualThread(() -> testPlanExecuteService.testPlanOrGroupRerun(execTask, userId)); + } +}