diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/controller/TestPlanExecuteController.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/controller/TestPlanExecuteController.java index 54e1450961..246d464f5b 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/controller/TestPlanExecuteController.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/controller/TestPlanExecuteController.java @@ -51,7 +51,9 @@ public class TestPlanExecuteController { @Log(type = OperationLogType.EXECUTE, expression = "#msClass.batchExecuteLog(#request)", msClass = TestPlanLogService.class) public void startExecute(@Validated @RequestBody TestPlanBatchExecuteRequest request) { testPlanManagementService.checkModuleIsOpen(request.getProjectId(), TestPlanResourceConfig.CHECK_TYPE_PROJECT, Collections.singletonList(TestPlanResourceConfig.CONFIG_TEST_PLAN)); - testPlanExecuteService.batchExecuteTestPlan(request, SessionUtils.getUserId()); + Thread.startVirtualThread(() -> + testPlanExecuteService.batchExecuteTestPlan(request, SessionUtils.getUserId()) + ); } } diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/job/TestPlanScheduleJob.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/job/TestPlanScheduleJob.java index 40262c5869..cc62357d9c 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/job/TestPlanScheduleJob.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/job/TestPlanScheduleJob.java @@ -6,6 +6,7 @@ import io.metersphere.sdk.constants.ApiBatchRunMode; import io.metersphere.sdk.constants.ApiExecuteRunMode; import io.metersphere.sdk.util.CommonBeanFactory; import io.metersphere.sdk.util.JSON; +import io.metersphere.sdk.util.LogUtils; import io.metersphere.system.schedule.BaseScheduleJob; import org.quartz.JobExecutionContext; import org.quartz.JobKey; @@ -21,13 +22,14 @@ public class TestPlanScheduleJob extends BaseScheduleJob { assert testPlanExecuteService != null; Map runConfig = JSON.parseObject(context.getJobDetail().getJobDataMap().get("config").toString(), Map.class); String runMode = runConfig.containsKey("runMode") ? runConfig.get("runMode") : ApiBatchRunMode.SERIAL.name(); - Thread.startVirtualThread(() -> { + LogUtils.info("开始执行测试计划的定时任务. ID:" + resourceId); + Thread.startVirtualThread(() -> testPlanExecuteService.singleExecuteTestPlan(new TestPlanExecuteRequest() {{ this.setExecuteId(resourceId); this.setRunMode(runMode); this.setExecutionSource(ApiExecuteRunMode.SCHEDULE.name()); - }}, userId); - }); + }}, userId) + ); } diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanBatchOperationService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanBatchOperationService.java index a0e3f6aed9..d1740fa7fe 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanBatchOperationService.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanBatchOperationService.java @@ -86,10 +86,13 @@ public class TestPlanBatchOperationService extends TestPlanBaseUtilsService { List movePlanIds = new ArrayList<>(); for (TestPlan testPlan : testPlanList) { + // 已归档的测试计划无法操作 + if (StringUtils.equalsIgnoreCase(testPlan.getStatus(), TestPlanConstants.TEST_PLAN_STATUS_ARCHIVED)) { + throw new MSException(Translator.get("test_plan.is.archived")); + } // 已归档的测试计划无法操作 测试计划组无法操作 - if (StringUtils.equalsIgnoreCase(testPlan.getStatus(), TestPlanConstants.TEST_PLAN_STATUS_ARCHIVED) - || StringUtils.equalsIgnoreCase(testPlan.getType(), TestPlanConstants.TEST_PLAN_TYPE_GROUP)) { - continue; + if (StringUtils.equalsIgnoreCase(testPlan.getType(), TestPlanConstants.TEST_PLAN_TYPE_GROUP)) { + throw new MSException(Translator.get("test_plan.group.error")); } movePlanIds.add(testPlan.getId()); } @@ -195,6 +198,8 @@ public class TestPlanBatchOperationService extends TestPlanBaseUtilsService { testPlan.setModuleId(moduleId); testPlan.setGroupId(groupId); testPlan.setPos(pos); + testPlan.setActualEndTime(null); + testPlan.setActualStartTime(null); testPlan.setStatus(TestPlanConstants.TEST_PLAN_STATUS_PREPARED); testPlanMapper.insert(testPlan); @@ -282,6 +287,8 @@ public class TestPlanBatchOperationService extends TestPlanBaseUtilsService { testPlanGroup.setUpdateUser(operator); testPlanGroup.setUpdateTime(operatorTime); testPlanGroup.setModuleId(moduleId); + testPlanGroup.setActualEndTime(null); + testPlanGroup.setActualStartTime(null); testPlanGroup.setStatus(TestPlanConstants.TEST_PLAN_STATUS_PREPARED); testPlanMapper.insert(testPlanGroup); diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanLogService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanLogService.java index 4338951ba2..4153187b64 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanLogService.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanLogService.java @@ -257,7 +257,7 @@ public class TestPlanLogService { } private String getLogModule(TestPlan testPlan) { - if (StringUtils.equalsIgnoreCase(testPlan.getStatus(), TestPlanConstants.TEST_PLAN_TYPE_PLAN)) { + if (StringUtils.equalsIgnoreCase(testPlan.getType(), TestPlanConstants.TEST_PLAN_TYPE_PLAN)) { return OperationLogModule.TEST_PLAN_TEST_PLAN; } else { return OperationLogModule.TEST_PLAN_TEST_PLAN_GROUP; diff --git a/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanExecuteTests.java b/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanExecuteTests.java index 6912a33ce4..083c4feafe 100644 --- a/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanExecuteTests.java +++ b/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanExecuteTests.java @@ -45,7 +45,6 @@ public class TestPlanExecuteTests extends BaseTest { private static TestPlan noGroupPlan; private static final String URL_POST_TEST_PLAN_SINGLE_EXECUTE = "/test-plan-execute/single"; - private static final String URL_POST_TEST_PLAN_BATCH_EXECUTE = "/test-plan-execute/batch"; @Resource private CommonProjectService commonProjectService; @@ -242,8 +241,7 @@ public class TestPlanExecuteTests extends BaseTest { batchExecuteRequest.setExecuteIds(execIds); batchExecuteRequest.setProjectId(project.getId()); batchExecuteRequest.setRunMode(runMode); - - this.requestPostWithOk(URL_POST_TEST_PLAN_BATCH_EXECUTE, batchExecuteRequest); + testPlanExecuteService.batchExecuteTestPlan(batchExecuteRequest, "admin"); //检查队列 List allQueueIds = new ArrayList<>();