fix(接口测试): 执行队列异常保护清理失败队列
This commit is contained in:
parent
6ee4272612
commit
555793c747
|
@ -1,7 +1,6 @@
|
|||
package io.metersphere.api.jmeter;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import io.metersphere.api.dto.RunRequest;
|
||||
import io.metersphere.api.exec.queue.ExecThreadPoolExecutor;
|
||||
import io.metersphere.api.exec.utils.GenerateHashTreeUtil;
|
||||
import io.metersphere.api.service.ApiScenarioReportService;
|
||||
|
@ -155,18 +154,12 @@ public class JMeterService {
|
|||
ResponseEntity<String> result = restTemplate.postForEntity(uri, request, String.class);
|
||||
if (result == null || !StringUtils.equals("SUCCESS", result.getBody())) {
|
||||
RemakeReportService remakeReportService = CommonBeanFactory.getBean(RemakeReportService.class);
|
||||
RunRequest runRequest = new RunRequest();
|
||||
runRequest.setTestId(request.getTestId());
|
||||
runRequest.setRunMode(request.getRunMode());
|
||||
remakeReportService.remake(request);
|
||||
LoggerUtil.error("发送请求[ " + request.getTestId() + " ] 到" + uri + " 节点执行失败");
|
||||
LoggerUtil.info(result.getBody());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
RemakeReportService remakeReportService = CommonBeanFactory.getBean(RemakeReportService.class);
|
||||
RunRequest runRequest = new RunRequest();
|
||||
runRequest.setTestId(request.getTestId());
|
||||
runRequest.setRunMode(request.getRunMode());
|
||||
remakeReportService.remake(request);
|
||||
LoggerUtil.error("发送请求[ " + request.getTestId() + " ] 执行失败:" + e.getMessage());
|
||||
LoggerUtil.error(e);
|
||||
|
|
|
@ -11,7 +11,6 @@ import io.metersphere.base.mapper.ApiExecutionQueueDetailMapper;
|
|||
import io.metersphere.base.mapper.ApiScenarioMapper;
|
||||
import io.metersphere.base.mapper.TestPlanApiScenarioMapper;
|
||||
import io.metersphere.commons.constants.ApiRunMode;
|
||||
import io.metersphere.commons.exception.MSException;
|
||||
import io.metersphere.commons.utils.CommonBeanFactory;
|
||||
import io.metersphere.commons.utils.FileUtils;
|
||||
import io.metersphere.commons.utils.LogUtil;
|
||||
|
@ -70,7 +69,7 @@ public class ApiJmeterFileService {
|
|||
if (detail != null && StringUtils.isNotEmpty(detail.getEvnMap())) {
|
||||
envMap = JSON.parseObject(detail.getEvnMap(), Map.class);
|
||||
}
|
||||
HashTree hashTree;
|
||||
HashTree hashTree = null;
|
||||
if (StringUtils.equalsAnyIgnoreCase(runMode, ApiRunMode.DEFINITION.name(), ApiRunMode.JENKINS_API_PLAN.name(), ApiRunMode.API_PLAN.name(), ApiRunMode.SCHEDULE_API_PLAN.name(), ApiRunMode.MANUAL_PLAN.name())) {
|
||||
hashTree = apiScenarioSerialService.generateHashTree(remoteTestId, reportId, runMode, envMap);
|
||||
} else {
|
||||
|
@ -78,7 +77,8 @@ public class ApiJmeterFileService {
|
|||
scenario = apiScenarioMapper.selectByPrimaryKey(remoteTestId);
|
||||
}
|
||||
if (scenario == null) {
|
||||
MSException.throwException("未找到执行场景。");
|
||||
// 清除队列
|
||||
executionQueueDetailMapper.deleteByPrimaryKey(queueId);
|
||||
}
|
||||
if (envMap != null && !envMap.isEmpty()) {
|
||||
planEnvMap = envMap;
|
||||
|
@ -92,7 +92,11 @@ public class ApiJmeterFileService {
|
|||
planEnvMap = environmentGroupProjectService.getEnvMap(envGroupId);
|
||||
}
|
||||
}
|
||||
try {
|
||||
hashTree = GenerateHashTreeUtil.generateHashTree(scenario, reportId, planEnvMap, reportType);
|
||||
} catch (Exception e) {
|
||||
executionQueueDetailMapper.deleteByPrimaryKey(queueId);
|
||||
}
|
||||
}
|
||||
return zipFilesToByteArray((reportId + "_" + remoteTestId), hashTree);
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@ import io.metersphere.commons.constants.ApiRunMode;
|
|||
import io.metersphere.commons.utils.BeanUtils;
|
||||
import io.metersphere.commons.utils.CommonBeanFactory;
|
||||
import io.metersphere.commons.utils.LogUtil;
|
||||
import io.metersphere.constants.RunModeConstants;
|
||||
import io.metersphere.dto.JmeterRunRequestDTO;
|
||||
import io.metersphere.dto.ResultDTO;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
@ -109,7 +108,6 @@ public class RemakeReportService {
|
|||
}
|
||||
}
|
||||
// 处理队列
|
||||
if (StringUtils.equals(request.getReportType(), RunModeConstants.SET_REPORT.toString())) {
|
||||
ApiExecutionQueueDetailExample example = new ApiExecutionQueueDetailExample();
|
||||
example.createCriteria().andQueueIdEqualTo(request.getQueueId()).andTestIdEqualTo(request.getTestId());
|
||||
CommonBeanFactory.getBean(ApiExecutionQueueDetailMapper.class).deleteByExample(example);
|
||||
|
@ -118,7 +116,6 @@ public class RemakeReportService {
|
|||
dto.setQueueId(request.getQueueId());
|
||||
dto.setTestId(request.getTestId());
|
||||
CommonBeanFactory.getBean(ApiExecutionQueueService.class).queueNext(dto);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LogUtil.error(e);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue