fix(测试计划): 修复测试计划用例执行触发方式错误问题

--bug=1009267 --user=赵勇 [github #8888]测试计划包含接口测试时,执行测试计划会出现接口执行一直是运行中状态,而且执行方式也有问题 https://www.tapd.cn/55049933/s/1087536
This commit is contained in:
fit2-zhao 2021-12-28 10:56:17 +08:00 committed by fit2-zhao
parent 23b0e3f511
commit ece30da5f9
5 changed files with 12 additions and 23 deletions

View File

@ -15,6 +15,7 @@ import io.metersphere.base.mapper.ApiDefinitionExecResultMapper;
import io.metersphere.base.mapper.TestPlanApiCaseMapper; import io.metersphere.base.mapper.TestPlanApiCaseMapper;
import io.metersphere.commons.constants.APITestStatus; import io.metersphere.commons.constants.APITestStatus;
import io.metersphere.commons.constants.ApiRunMode; import io.metersphere.commons.constants.ApiRunMode;
import io.metersphere.commons.constants.TriggerMode;
import io.metersphere.constants.RunModeConstants; import io.metersphere.constants.RunModeConstants;
import io.metersphere.dto.JmeterRunRequestDTO; import io.metersphere.dto.JmeterRunRequestDTO;
import io.metersphere.dto.MsExecResponseDTO; import io.metersphere.dto.MsExecResponseDTO;
@ -54,6 +55,7 @@ public class TestPlanApiExecuteService {
if (CollectionUtils.isEmpty(ids)) { if (CollectionUtils.isEmpty(ids)) {
return new LinkedList<>(); return new LinkedList<>();
} }
LoggerUtil.debug("开始查询测试计划用例");
TestPlanApiCaseExample example = new TestPlanApiCaseExample(); TestPlanApiCaseExample example = new TestPlanApiCaseExample();
example.createCriteria().andIdIn(ids); example.createCriteria().andIdIn(ids);
example.setOrderByClause("`order` DESC"); example.setOrderByClause("`order` DESC");
@ -80,9 +82,11 @@ public class TestPlanApiExecuteService {
SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory); SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory);
} }
LoggerUtil.debug("开始生成测试计划队列");
String reportType = request.getConfig() != null ? request.getConfig().getReportType() : null; String reportType = request.getConfig() != null ? request.getConfig().getReportType() : null;
String poolId = request.getConfig() != null ? request.getConfig().getResourcePoolId() : null; String poolId = request.getConfig() != null ? request.getConfig().getResourcePoolId() : null;
DBTestQueue deQueue = apiExecutionQueueService.add(executeQueue, poolId, ApiRunMode.API_PLAN.name(), request.getPlanReportId(), reportType, request.getTriggerMode()); String runMode = StringUtils.equals(request.getTriggerMode(), TriggerMode.MANUAL.name()) ? ApiRunMode.API_PLAN.name() : ApiRunMode.SCHEDULE_API_PLAN.name();
DBTestQueue deQueue = apiExecutionQueueService.add(executeQueue, poolId, ApiRunMode.API_PLAN.name(), request.getPlanReportId(), reportType, runMode);
//如果是测试计划生成报告的执行则更新执行信息执行线程信息 //如果是测试计划生成报告的执行则更新执行信息执行线程信息
if (TestPlanReportExecuteCatch.containsReport(request.getPlanReportId())) { if (TestPlanReportExecuteCatch.containsReport(request.getPlanReportId())) {
@ -92,12 +96,12 @@ public class TestPlanApiExecuteService {
} }
// 开始选择执行模式 // 开始选择执行模式
if (request.getConfig() != null && request.getConfig().getMode().equals(RunModeConstants.SERIAL.toString())) { if (request.getConfig() != null && request.getConfig().getMode().equals(RunModeConstants.SERIAL.toString())) {
// 开始串行执行 LoggerUtil.debug("开始串行执行");
if (deQueue != null && deQueue.getQueue() != null) { if (deQueue != null && deQueue.getQueue() != null) {
apiScenarioSerialService.serial(deQueue, deQueue.getQueue()); apiScenarioSerialService.serial(deQueue, deQueue.getQueue());
} }
} else { } else {
// 开始并发执行 LoggerUtil.debug("开始并发执行");
if (deQueue != null && deQueue.getQueue() != null) { if (deQueue != null && deQueue.getQueue() != null) {
parallel(executeQueue, request, deQueue); parallel(executeQueue, request, deQueue);
} }
@ -119,7 +123,8 @@ public class TestPlanApiExecuteService {
if (request.getConfig() == null || !GenerateHashTreeUtil.isResourcePool(request.getConfig().getResourcePoolId()).isPool()) { if (request.getConfig() == null || !GenerateHashTreeUtil.isResourcePool(request.getConfig().getResourcePoolId()).isPool()) {
hashTree = apiScenarioSerialService.generateHashTree(testPlanApiCase.getId()); hashTree = apiScenarioSerialService.generateHashTree(testPlanApiCase.getId());
} }
JmeterRunRequestDTO runRequest = new JmeterRunRequestDTO(testPlanApiCase.getId(), reportId, request.getTriggerMode(), hashTree); String runMode = StringUtils.equals(request.getTriggerMode(), TriggerMode.MANUAL.name()) ? ApiRunMode.API_PLAN.name() : ApiRunMode.SCHEDULE_API_PLAN.name();
JmeterRunRequestDTO runRequest = new JmeterRunRequestDTO(testPlanApiCase.getId(), reportId, runMode, hashTree);
if (request.getConfig() != null) { if (request.getConfig() != null) {
runRequest.setPool(GenerateHashTreeUtil.isResourcePool(request.getConfig().getResourcePoolId())); runRequest.setPool(GenerateHashTreeUtil.isResourcePool(request.getConfig().getResourcePoolId()));
runRequest.setPoolId(request.getConfig().getResourcePoolId()); runRequest.setPoolId(request.getConfig().getResourcePoolId());

View File

@ -46,13 +46,7 @@ public class ApiDefinitionExecResultUtil {
if (caseWithBLOBs != null) { if (caseWithBLOBs != null) {
apiResult.setName(caseWithBLOBs.getName()); apiResult.setName(caseWithBLOBs.getName());
} }
if (StringUtils.equalsIgnoreCase(request.getTriggerMode(), ApiRunMode.SCHEDULE_API_PLAN.name())) { apiResult.setTriggerMode(request.getTriggerMode());
apiResult.setTriggerMode(TriggerMode.SCHEDULE.name());
} else if (StringUtils.equalsIgnoreCase(request.getTriggerMode(), ApiRunMode.JENKINS_API_PLAN.name())) {
apiResult.setTriggerMode(TriggerMode.MANUAL.name());
} else {
apiResult.setTriggerMode(TriggerMode.BATCH.name());
}
apiResult.setActuator("LOCAL"); apiResult.setActuator("LOCAL");
if (request.getConfig() != null && GenerateHashTreeUtil.isResourcePool(request.getConfig().getResourcePoolId()).isPool()) { if (request.getConfig() != null && GenerateHashTreeUtil.isResourcePool(request.getConfig().getResourcePoolId()).isPool()) {
apiResult.setActuator(request.getConfig().getResourcePoolId()); apiResult.setActuator(request.getConfig().getResourcePoolId());

View File

@ -325,9 +325,6 @@ public class ApiDefinitionExecResultService {
saveResult.setId(reportId); saveResult.setId(reportId);
saveResult.setActuator("LOCAL"); saveResult.setActuator("LOCAL");
saveResult.setName(item.getName()); saveResult.setName(item.getName());
if (StringUtils.equals(type, TriggerMode.SCHEDULE.name())) {
saveResult.setTriggerMode(TriggerMode.SCHEDULE.name());
}
saveResult.setType(type); saveResult.setType(type);
saveResult.setCreateTime(item.getStartTime()); saveResult.setCreateTime(item.getStartTime());
if (SessionUtils.getUser() != null) { if (SessionUtils.getUser() != null) {

View File

@ -1152,13 +1152,7 @@ public class TestPlanService {
private void executeApiTestCase(String triggerMode, String planReportId, String userId, List<String> planCaseIds, RunModeConfigDTO runModeConfig) { private void executeApiTestCase(String triggerMode, String planReportId, String userId, List<String> planCaseIds, RunModeConfigDTO runModeConfig) {
BatchRunDefinitionRequest request = new BatchRunDefinitionRequest(); BatchRunDefinitionRequest request = new BatchRunDefinitionRequest();
if (StringUtils.equals(triggerMode, ReportTriggerMode.API.name())) { request.setTriggerMode(triggerMode);
request.setTriggerMode(ApiRunMode.JENKINS_API_PLAN.name());
} else if (StringUtils.equals(triggerMode, ReportTriggerMode.MANUAL.name())) {
request.setTriggerMode(ApiRunMode.MANUAL_PLAN.name());
} else {
request.setTriggerMode(ApiRunMode.SCHEDULE_API_PLAN.name());
}
request.setPlanIds(planCaseIds); request.setPlanIds(planCaseIds);
request.setPlanReportId(planReportId); request.setPlanReportId(planReportId);
request.setConfig(runModeConfig); request.setConfig(runModeConfig);
@ -1912,7 +1906,6 @@ public class TestPlanService {
} }
public String runPlan(TestplanRunRequest testplanRunRequest) { public String runPlan(TestplanRunRequest testplanRunRequest) {
String envType = testplanRunRequest.getEnvironmentType(); String envType = testplanRunRequest.getEnvironmentType();
Map<String, String> envMap = testplanRunRequest.getEnvMap(); Map<String, String> envMap = testplanRunRequest.getEnvMap();
String environmentGroupId = testplanRunRequest.getEnvironmentGroupId(); String environmentGroupId = testplanRunRequest.getEnvironmentGroupId();

View File

@ -575,7 +575,7 @@ export default {
}); });
}, },
handleRunBatch(config) { handleRunBatch(config) {
let obj = {planIds: this.testPlanCaseIds, config: config}; let obj = {planIds: this.testPlanCaseIds, config: config, triggerMode:"BATCH"};
this.$post("/test/plan/api/case/run", obj, response => { this.$post("/test/plan/api/case/run", obj, response => {
this.$message(this.$t('commons.run_message')); this.$message(this.$t('commons.run_message'));
this.$refs.taskCenter.open(); this.$refs.taskCenter.open();