refactor(测试计划): 优化测试计划状态的计算方式
This commit is contained in:
parent
2558978c6f
commit
68231064cb
|
@ -143,7 +143,7 @@ public class TestPlanFunctionalCaseController {
|
|||
@CheckOwner(resourceId = "#request.getTestPlanId()", resourceType = "test_plan")
|
||||
public void run(@Validated @RequestBody TestPlanCaseRunRequest request) {
|
||||
testPlanFunctionalCaseService.run(request, new LogInsertModule(SessionUtils.getUserId(), "/test-plan/functional/case/run", HttpMethodConstants.POST.name()));
|
||||
extTestPlanMapper.setActualStartTime(request.getTestPlanId(), System.currentTimeMillis());
|
||||
testPlanService.setActualStartTime(request.getTestPlanId());
|
||||
testPlanService.refreshTestPlanStatus(request.getTestPlanId());
|
||||
}
|
||||
|
||||
|
@ -153,7 +153,7 @@ public class TestPlanFunctionalCaseController {
|
|||
@CheckOwner(resourceId = "#request.getTestPlanId()", resourceType = "test_plan")
|
||||
public void batchRun(@Validated @RequestBody TestPlanCaseBatchRunRequest request) {
|
||||
testPlanFunctionalCaseService.batchRun(request, new LogInsertModule(SessionUtils.getUserId(), "/test-plan/functional/case/batch/run", HttpMethodConstants.POST.name()));
|
||||
extTestPlanMapper.setActualStartTime(request.getTestPlanId(), System.currentTimeMillis());
|
||||
testPlanService.setActualStartTime(request.getTestPlanId());
|
||||
testPlanService.refreshTestPlanStatus(request.getTestPlanId());
|
||||
}
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@ import io.metersphere.sdk.constants.CommonConstants;
|
|||
import io.metersphere.sdk.dto.api.task.*;
|
||||
import io.metersphere.sdk.dto.queue.ExecutionQueue;
|
||||
import io.metersphere.sdk.dto.queue.ExecutionQueueDetail;
|
||||
import io.metersphere.sdk.util.CommonBeanFactory;
|
||||
import io.metersphere.sdk.util.LogUtils;
|
||||
import io.metersphere.sdk.util.SubListUtils;
|
||||
import jakarta.annotation.Resource;
|
||||
|
@ -83,7 +84,9 @@ public class TestPlanApiCaseBatchRunService {
|
|||
* @param userId
|
||||
*/
|
||||
public void asyncBatchRun(TestPlanApiCaseBatchRunRequest request, String userId) {
|
||||
extTestPlanMapper.setActualStartTime(request.getTestPlanId(), System.currentTimeMillis());
|
||||
TestPlanService testPlanService = CommonBeanFactory.getBean(TestPlanService.class);
|
||||
testPlanService.setTestPlanUnderway(request.getTestPlanId());
|
||||
testPlanService.setActualStartTime(request.getTestPlanId());
|
||||
Thread.startVirtualThread(() -> batchRun(request, userId));
|
||||
}
|
||||
|
||||
|
|
|
@ -34,6 +34,7 @@ import io.metersphere.sdk.dto.api.task.*;
|
|||
import io.metersphere.sdk.exception.MSException;
|
||||
import io.metersphere.sdk.mapper.EnvironmentMapper;
|
||||
import io.metersphere.sdk.util.BeanUtils;
|
||||
import io.metersphere.sdk.util.CommonBeanFactory;
|
||||
import io.metersphere.sdk.util.Translator;
|
||||
import io.metersphere.system.dto.LogInsertModule;
|
||||
import io.metersphere.system.dto.sdk.BaseTreeNode;
|
||||
|
@ -640,7 +641,9 @@ public class TestPlanApiCaseService extends TestPlanResourceService {
|
|||
|
||||
public TaskRequestDTO run(String id, String reportId, String userId) {
|
||||
TestPlanApiCase testPlanApiCase = checkResourceExist(id);
|
||||
extTestPlanMapper.setActualStartTime(testPlanApiCase.getTestPlanId(), System.currentTimeMillis());
|
||||
TestPlanService testPlanService = CommonBeanFactory.getBean(TestPlanService.class);
|
||||
testPlanService.setTestPlanUnderway(testPlanApiCase.getTestPlanId());
|
||||
testPlanService.setActualStartTime(testPlanApiCase.getTestPlanId());
|
||||
ApiTestCase apiTestCase = apiTestCaseService.checkResourceExist(testPlanApiCase.getApiCaseId());
|
||||
ApiRunModeConfigDTO runModeConfig = testPlanApiBatchRunBaseService.getApiRunModeConfig(testPlanApiCase.getTestPlanCollectionId());
|
||||
runModeConfig.setEnvironmentId(apiBatchRunBaseService.getEnvId(runModeConfig, testPlanApiCase.getEnvironmentId()));
|
||||
|
|
|
@ -25,6 +25,7 @@ import io.metersphere.sdk.constants.TaskTriggerMode;
|
|||
import io.metersphere.sdk.dto.api.task.*;
|
||||
import io.metersphere.sdk.dto.queue.ExecutionQueue;
|
||||
import io.metersphere.sdk.dto.queue.ExecutionQueueDetail;
|
||||
import io.metersphere.sdk.util.CommonBeanFactory;
|
||||
import io.metersphere.sdk.util.DateUtils;
|
||||
import io.metersphere.sdk.util.LogUtils;
|
||||
import io.metersphere.sdk.util.SubListUtils;
|
||||
|
@ -82,7 +83,9 @@ public class TestPlanApiScenarioBatchRunService {
|
|||
* @param userId
|
||||
*/
|
||||
public void asyncBatchRun(TestPlanApiScenarioBatchRunRequest request, String userId) {
|
||||
extTestPlanMapper.setActualStartTime(request.getTestPlanId(), System.currentTimeMillis());
|
||||
TestPlanService testPlanService = CommonBeanFactory.getBean(TestPlanService.class);
|
||||
testPlanService.setActualStartTime(request.getTestPlanId());
|
||||
testPlanService.setTestPlanUnderway(request.getTestPlanId());
|
||||
Thread.startVirtualThread(() -> batchRun(request, userId));
|
||||
}
|
||||
|
||||
|
|
|
@ -36,6 +36,7 @@ import io.metersphere.sdk.dto.api.task.*;
|
|||
import io.metersphere.sdk.exception.MSException;
|
||||
import io.metersphere.sdk.mapper.EnvironmentMapper;
|
||||
import io.metersphere.sdk.util.BeanUtils;
|
||||
import io.metersphere.sdk.util.CommonBeanFactory;
|
||||
import io.metersphere.sdk.util.Translator;
|
||||
import io.metersphere.system.dto.LogInsertModule;
|
||||
import io.metersphere.system.dto.sdk.BaseTreeNode;
|
||||
|
@ -292,7 +293,9 @@ public class TestPlanApiScenarioService extends TestPlanResourceService {
|
|||
|
||||
public TaskRequestDTO run(String id, String reportId, String userId) {
|
||||
TestPlanApiScenario testPlanApiScenario = checkResourceExist(id);
|
||||
extTestPlanMapper.setActualStartTime(testPlanApiScenario.getTestPlanId(), System.currentTimeMillis());
|
||||
TestPlanService testPlanService = CommonBeanFactory.getBean(TestPlanService.class);
|
||||
testPlanService.setTestPlanUnderway(testPlanApiScenario.getTestPlanId());
|
||||
testPlanService.setActualStartTime(testPlanApiScenario.getTestPlanId());
|
||||
ApiScenario apiScenario = apiScenarioService.checkResourceExist(testPlanApiScenario.getApiScenarioId());
|
||||
ApiRunModeConfigDTO runModeConfig = testPlanApiBatchRunBaseService.getApiRunModeConfig(testPlanApiScenario.getTestPlanCollectionId());
|
||||
runModeConfig.setEnvironmentId(apiBatchRunBaseService.getEnvId(runModeConfig, testPlanApiScenario.getEnvironmentId()));
|
||||
|
|
|
@ -7,11 +7,7 @@ import io.metersphere.plan.dto.request.TestPlanBatchExecuteRequest;
|
|||
import io.metersphere.plan.dto.request.TestPlanExecuteRequest;
|
||||
import io.metersphere.plan.dto.request.TestPlanReportGenRequest;
|
||||
import io.metersphere.plan.mapper.*;
|
||||
import io.metersphere.sdk.constants.ApiBatchRunMode;
|
||||
import io.metersphere.sdk.constants.CaseType;
|
||||
import io.metersphere.sdk.constants.ExecStatus;
|
||||
import io.metersphere.sdk.constants.TaskTriggerMode;
|
||||
import io.metersphere.sdk.constants.TestPlanConstants;
|
||||
import io.metersphere.sdk.constants.*;
|
||||
import io.metersphere.sdk.dto.queue.TestPlanExecutionQueue;
|
||||
import io.metersphere.sdk.exception.MSException;
|
||||
import io.metersphere.sdk.util.JSON;
|
||||
|
@ -221,6 +217,10 @@ public class TestPlanExecuteService {
|
|||
genReportRequest.setTestPlanId(executionQueue.getSourceID());
|
||||
genReportRequest.setProjectId(testPlan.getProjectId());
|
||||
if (StringUtils.equalsIgnoreCase(testPlan.getType(), TestPlanConstants.TEST_PLAN_TYPE_GROUP)) {
|
||||
|
||||
testPlanService.setActualStartTime(executionQueue.getSourceID());
|
||||
testPlanService.setTestPlanUnderway(executionQueue.getSourceID());
|
||||
|
||||
List<TestPlan> children = testPlanService.selectNotArchivedChildren(testPlan.getId());
|
||||
// 预生成计划组报告
|
||||
Map<String, String> reportMap = testPlanReportService.genReportByExecution(executionQueue.getPrepareReportId(), genReportRequest, executionQueue.getCreateUser());
|
||||
|
@ -279,7 +279,8 @@ public class TestPlanExecuteService {
|
|||
|
||||
//执行测试计划里不同类型的用例 回调:caseTypeExecuteQueueFinish
|
||||
public void executeTestPlan(TestPlanExecutionQueue executionQueue) {
|
||||
extTestPlanMapper.setActualStartTime(executionQueue.getSourceID(), System.currentTimeMillis());
|
||||
testPlanService.setActualStartTime(executionQueue.getSourceID());
|
||||
testPlanService.setTestPlanUnderway(executionQueue.getSourceID());
|
||||
TestPlan testPlan = testPlanMapper.selectByPrimaryKey(executionQueue.getSourceID());
|
||||
TestPlanCollectionExample testPlanCollectionExample = new TestPlanCollectionExample();
|
||||
testPlanCollectionExample.createCriteria().andTestPlanIdEqualTo(testPlan.getId()).andParentIdEqualTo("NONE");
|
||||
|
|
|
@ -753,6 +753,48 @@ public class TestPlanService extends TestPlanBaseUtilsService {
|
|||
@Autowired
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
public void setTestPlanUnderway(String testPlanId) {
|
||||
this.updateTestPlanStatusAndGroupStatus(testPlanId, TestPlanConstants.TEST_PLAN_STATUS_UNDERWAY);
|
||||
}
|
||||
|
||||
public void setActualStartTime(String testPlanId) {
|
||||
long actualStartTime = System.currentTimeMillis();
|
||||
TestPlan testPlan = testPlanMapper.selectByPrimaryKey(testPlanId);
|
||||
if (testPlan != null) {
|
||||
extTestPlanMapper.setActualStartTime(testPlan.getId(), actualStartTime);
|
||||
if (!StringUtils.equalsIgnoreCase(testPlan.getGroupId(), TestPlanConstants.TEST_PLAN_DEFAULT_GROUP_ID)) {
|
||||
extTestPlanMapper.setActualStartTime(testPlan.getGroupId(), actualStartTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateTestPlanStatusAndGroupStatus(String testPlanId, String testPlanStatus) {
|
||||
TestPlan testPlan = new TestPlan();
|
||||
testPlan.setId(testPlanId);
|
||||
testPlan.setStatus(testPlanStatus);
|
||||
testPlanMapper.updateByPrimaryKeySelective(testPlan);
|
||||
|
||||
testPlan = testPlanMapper.selectByPrimaryKey(testPlanId);
|
||||
if (!StringUtils.equalsIgnoreCase(testPlan.getGroupId(), TestPlanConstants.TEST_PLAN_DEFAULT_GROUP_ID)) {
|
||||
//该测试计划是测试计划组内的子计划, 要同步计算测试计划组的状态
|
||||
List<TestPlan> childPlan = this.selectNotArchivedChildren(testPlan.getGroupId());
|
||||
if (CollectionUtils.isNotEmpty(childPlan)) {
|
||||
TestPlan updateGroupPlan = new TestPlan();
|
||||
updateGroupPlan.setId(testPlan.getGroupId());
|
||||
if (childPlan.stream().allMatch(item -> StringUtils.equals(item.getStatus(), TestPlanConstants.TEST_PLAN_STATUS_COMPLETED))) {
|
||||
updateGroupPlan.setStatus(TestPlanConstants.TEST_PLAN_STATUS_COMPLETED);
|
||||
} else {
|
||||
updateGroupPlan.setStatus(TestPlanConstants.TEST_PLAN_STATUS_UNDERWAY);
|
||||
}
|
||||
testPlanMapper.updateByPrimaryKeySelective(updateGroupPlan);
|
||||
|
||||
if (StringUtils.equalsIgnoreCase(updateGroupPlan.getStatus(), TestPlanConstants.TEST_PLAN_STATUS_COMPLETED)) {
|
||||
extTestPlanMapper.setActualEndTime(testPlan.getGroupId(), System.currentTimeMillis());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void refreshTestPlanStatus(String testPlanId) {
|
||||
Map<String, Long> caseExecResultCount = new HashMap<>();
|
||||
Map<String, TestPlanResourceService> beansOfType = applicationContext.getBeansOfType(TestPlanResourceService.class);
|
||||
|
@ -779,28 +821,8 @@ public class TestPlanService extends TestPlanBaseUtilsService {
|
|||
testPlanFinalStatus = TestPlanConstants.TEST_PLAN_STATUS_COMPLETED;
|
||||
extTestPlanMapper.setActualEndTime(testPlanId, System.currentTimeMillis());
|
||||
}
|
||||
TestPlan testPlan = new TestPlan();
|
||||
testPlan.setId(testPlanId);
|
||||
testPlan.setStatus(testPlanFinalStatus);
|
||||
testPlanMapper.updateByPrimaryKeySelective(testPlan);
|
||||
|
||||
testPlan = testPlanMapper.selectByPrimaryKey(testPlanId);
|
||||
|
||||
if (!StringUtils.equalsIgnoreCase(testPlan.getGroupId(), TestPlanConstants.TEST_PLAN_DEFAULT_GROUP_ID)) {
|
||||
//该测试计划是测试计划组内的子计划, 要同步计算测试计划组的状态
|
||||
|
||||
List<TestPlan> childPlan = this.selectNotArchivedChildren(testPlan.getGroupId());
|
||||
if (CollectionUtils.isNotEmpty(childPlan)) {
|
||||
TestPlan updateGroupPlan = new TestPlan();
|
||||
updateGroupPlan.setId(testPlan.getGroupId());
|
||||
if (childPlan.stream().allMatch(item -> StringUtils.equals(item.getStatus(), TestPlanConstants.TEST_PLAN_STATUS_COMPLETED))) {
|
||||
updateGroupPlan.setStatus(TestPlanConstants.TEST_PLAN_STATUS_COMPLETED);
|
||||
} else {
|
||||
updateGroupPlan.setStatus(TestPlanConstants.TEST_PLAN_STATUS_UNDERWAY);
|
||||
}
|
||||
testPlanMapper.updateByPrimaryKeySelective(updateGroupPlan);
|
||||
}
|
||||
}
|
||||
this.updateTestPlanStatusAndGroupStatus(testPlanId, testPlanFinalStatus);
|
||||
}
|
||||
|
||||
public TestPlanOperationResponse sortInGroup(PosRequest request, LogInsertModule logInsertModule) {
|
||||
|
|
Loading…
Reference in New Issue