feat(接口测试): 测试计划单接口和场景用例执行任务,重跑逻辑
--task=1016918 --user=陈建星 失败重跑 https://www.tapd.cn/55049933/s/1609836
This commit is contained in:
parent
21a004a39d
commit
a6a9d4ebca
|
@ -785,7 +785,6 @@ public class TestPlanApiCaseService extends TestPlanResourceService {
|
||||||
|
|
||||||
if (StringUtils.isEmpty(taskItem.getReportId())) {
|
if (StringUtils.isEmpty(taskItem.getReportId())) {
|
||||||
taskInfo.setRealTime(false);
|
taskInfo.setRealTime(false);
|
||||||
taskItem.setReportId(IDGenerator.nextStr());
|
|
||||||
} else {
|
} else {
|
||||||
// 如果传了报告ID,则实时获取结果
|
// 如果传了报告ID,则实时获取结果
|
||||||
taskInfo.setRealTime(true);
|
taskInfo.setRealTime(true);
|
||||||
|
@ -794,6 +793,30 @@ public class TestPlanApiCaseService extends TestPlanResourceService {
|
||||||
return apiExecuteService.execute(taskRequest);
|
return apiExecuteService.execute(taskRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void runRun(ExecTask execTask, ExecTaskItem execTaskItem, String userId) {
|
||||||
|
String id = execTaskItem.getResourceId();
|
||||||
|
TestPlanApiCase testPlanApiCase = checkResourceExist(id);
|
||||||
|
TestPlanService testPlanService = CommonBeanFactory.getBean(TestPlanService.class);
|
||||||
|
testPlanService.setActualStartTime(testPlanApiCase.getTestPlanId());
|
||||||
|
ApiTestCase apiTestCase = apiTestCaseService.checkResourceExist(testPlanApiCase.getApiCaseId());
|
||||||
|
ApiRunModeConfigDTO runModeConfig = testPlanApiBatchRunBaseService.getApiRunModeConfig(testPlanApiCase.getTestPlanCollectionId());
|
||||||
|
runModeConfig.setEnvironmentId(apiBatchRunBaseService.getEnvId(runModeConfig, testPlanApiCase.getEnvironmentId()));
|
||||||
|
runModeConfig.setRunMode(ApiBatchRunMode.PARALLEL.name());
|
||||||
|
TaskRequestDTO taskRequest = getTaskRequest(null, id, apiTestCase.getProjectId(), ApiExecuteRunMode.RUN.name());
|
||||||
|
|
||||||
|
TaskInfo taskInfo = taskRequest.getTaskInfo();
|
||||||
|
TaskItem taskItem = taskRequest.getTaskItem();
|
||||||
|
taskInfo.setTaskId(execTask.getId());
|
||||||
|
taskInfo.setRunModeConfig(runModeConfig);
|
||||||
|
taskInfo.setSaveResult(true);
|
||||||
|
taskInfo.setRealTime(true);
|
||||||
|
taskInfo.setUserId(userId);
|
||||||
|
taskItem.setId(execTaskItem.getId());
|
||||||
|
taskInfo.setRealTime(false);
|
||||||
|
|
||||||
|
apiExecuteService.execute(taskRequest);
|
||||||
|
}
|
||||||
|
|
||||||
public TestPlanApiCase checkResourceExist(String id) {
|
public TestPlanApiCase checkResourceExist(String id) {
|
||||||
return ServiceUtils.checkResourceExist(testPlanApiCaseMapper.selectByPrimaryKey(id), "api_test_case_not_exist");
|
return ServiceUtils.checkResourceExist(testPlanApiCaseMapper.selectByPrimaryKey(id), "api_test_case_not_exist");
|
||||||
}
|
}
|
||||||
|
@ -1008,4 +1031,5 @@ public class TestPlanApiCaseService extends TestPlanResourceService {
|
||||||
list.add(bugRelationCase);
|
list.add(bugRelationCase);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -387,6 +387,29 @@ public class TestPlanApiScenarioService extends TestPlanResourceService {
|
||||||
return apiExecuteService.execute(taskRequest);
|
return apiExecuteService.execute(taskRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void runRun(ExecTask execTask, ExecTaskItem execTaskItem, String userId) {
|
||||||
|
TestPlanApiScenario testPlanApiScenario = checkResourceExist(execTaskItem.getResourceId());
|
||||||
|
TestPlanService testPlanService = CommonBeanFactory.getBean(TestPlanService.class);
|
||||||
|
testPlanService.setActualStartTime(testPlanApiScenario.getTestPlanId());
|
||||||
|
ApiScenario apiScenario = apiScenarioService.checkResourceExist(testPlanApiScenario.getApiScenarioId());
|
||||||
|
ApiRunModeConfigDTO runModeConfig = testPlanApiBatchRunBaseService.getApiRunModeConfig(testPlanApiScenario.getTestPlanCollectionId());
|
||||||
|
runModeConfig.setEnvironmentId(apiBatchRunBaseService.getEnvId(runModeConfig, testPlanApiScenario.getEnvironmentId()));
|
||||||
|
TaskRequestDTO taskRequest = getTaskRequest(null, execTaskItem.getResourceId(), apiScenario.getProjectId(), ApiExecuteRunMode.RUN.name());
|
||||||
|
|
||||||
|
TaskInfo taskInfo = taskRequest.getTaskInfo();
|
||||||
|
taskInfo.setTaskId(execTask.getId());
|
||||||
|
taskInfo.setRunModeConfig(runModeConfig);
|
||||||
|
taskInfo.setSaveResult(true);
|
||||||
|
taskInfo.setRealTime(true);
|
||||||
|
taskInfo.setUserId(userId);
|
||||||
|
taskInfo.setRealTime(false);
|
||||||
|
|
||||||
|
TaskItem taskItem = taskRequest.getTaskItem();
|
||||||
|
taskItem.setId(execTaskItem.getId());
|
||||||
|
|
||||||
|
apiExecuteService.execute(taskRequest);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 预生成用例的执行报告
|
* 预生成用例的执行报告
|
||||||
*
|
*
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
package io.metersphere.plan.service.rerun;
|
||||||
|
|
||||||
|
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
|
||||||
|
* @CreateTime: 2024-02-06 20:47
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public class TestPlanApiCaseRerunService implements TaskRerunService {
|
||||||
|
@Resource
|
||||||
|
private TestPlanApiCaseService testPlanApiCaseService;
|
||||||
|
@Resource
|
||||||
|
private ExecTaskItemMapper execTaskItemMapper;
|
||||||
|
|
||||||
|
public TestPlanApiCaseRerunService() {
|
||||||
|
TaskRerunServiceInvoker.register(ExecTaskType.TEST_PLAN_API_CASE, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void rerun(ExecTask execTask, List<String> taskItemIds, String userId) {
|
||||||
|
ExecTaskItem execTaskItem = execTaskItemMapper.selectByPrimaryKey(taskItemIds.getFirst());
|
||||||
|
testPlanApiCaseService.runRun(execTask, execTaskItem, userId);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,37 @@
|
||||||
|
package io.metersphere.plan.service.rerun;
|
||||||
|
|
||||||
|
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
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public class TestPlanApiScenarioRerunService implements TaskRerunService {
|
||||||
|
@Resource
|
||||||
|
private TestPlanApiScenarioService testPlanApiScenarioService;
|
||||||
|
@Resource
|
||||||
|
private ExecTaskItemMapper execTaskItemMapper;
|
||||||
|
|
||||||
|
public TestPlanApiScenarioRerunService() {
|
||||||
|
TaskRerunServiceInvoker.register(ExecTaskType.TEST_PLAN_API_SCENARIO, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void rerun(ExecTask execTask, List<String> taskItemIds, String userId) {
|
||||||
|
ExecTaskItem execTaskItem = execTaskItemMapper.selectByPrimaryKey(taskItemIds.getFirst());
|
||||||
|
testPlanApiScenarioService.runRun(execTask, execTaskItem, userId);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue