fix(接口测试): 修复串行执行偶发异常造成阻塞问题
Signed-off-by: fit2-zhao <yong.zhao@fit2cloud.com>
This commit is contained in:
parent
b63af54422
commit
d2f30562b3
|
@ -83,7 +83,7 @@ public class ApiCaseSerialService {
|
|||
runRequest.getExtendedParameters().put(PROJECT_ID, queue.getProjectIds());
|
||||
jMeterService.run(runRequest);
|
||||
} catch (Exception e) {
|
||||
RequestParamsUtil.rollback(runRequest, e);
|
||||
LoggerUtil.error("串行执行用例失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@ import io.metersphere.commons.utils.GenerateHashTreeUtil;
|
|||
import io.metersphere.commons.utils.HashTreeUtil;
|
||||
import io.metersphere.commons.utils.JSON;
|
||||
import io.metersphere.commons.utils.RequestParamsUtil;
|
||||
import io.metersphere.constants.RunModeConstants;
|
||||
import io.metersphere.dto.JmeterRunRequestDTO;
|
||||
import io.metersphere.environment.service.BaseEnvironmentService;
|
||||
import io.metersphere.utils.LoggerUtil;
|
||||
|
@ -30,6 +31,7 @@ import org.springframework.stereotype.Service;
|
|||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
@ -60,6 +62,7 @@ public class ApiScenarioSerialService {
|
|||
reportId = queue.getReportId();
|
||||
}
|
||||
JmeterRunRequestDTO runRequest = RequestParamsUtil.init(executionQueue, queue, reportId);
|
||||
runRequest.setRunType(RunModeConstants.SERIAL.toString());
|
||||
// 更新报告状态
|
||||
updateReportToRunning(queue, runRequest);
|
||||
try {
|
||||
|
@ -98,7 +101,7 @@ public class ApiScenarioSerialService {
|
|||
runRequest.getExtendedParameters().put("projectId", queue.getProjectIds());
|
||||
jMeterService.run(runRequest);
|
||||
} catch (Exception e) {
|
||||
RequestParamsUtil.rollback(runRequest, e);
|
||||
LoggerUtil.error("串行执行失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -13,10 +13,12 @@ import io.metersphere.base.mapper.TestResourcePoolMapper;
|
|||
import io.metersphere.commons.constants.ElementConstants;
|
||||
import io.metersphere.commons.constants.ResourcePoolTypeEnum;
|
||||
import io.metersphere.constants.RunModeConstants;
|
||||
import io.metersphere.dto.*;
|
||||
import io.metersphere.dto.BaseSystemConfigDTO;
|
||||
import io.metersphere.dto.JmeterRunRequestDTO;
|
||||
import io.metersphere.dto.ProjectJarConfig;
|
||||
import io.metersphere.dto.RunModeConfigDTO;
|
||||
import io.metersphere.environment.service.BaseEnvGroupProjectService;
|
||||
import io.metersphere.plugin.core.MsTestElement;
|
||||
import io.metersphere.service.ApiExecutionQueueService;
|
||||
import io.metersphere.service.RemakeReportService;
|
||||
import io.metersphere.utils.LoggerUtil;
|
||||
import io.metersphere.vo.BooleanPool;
|
||||
|
@ -161,23 +163,15 @@ public class GenerateHashTreeUtil {
|
|||
|
||||
LoggerUtil.info("场景资源:" + item.getName() + ", 生成执行脚本JMX成功", runRequest.getReportId());
|
||||
} catch (Exception ex) {
|
||||
remakeException(runRequest, ex);
|
||||
LoggerUtil.error("场景资源:" + item.getName() + ", 生成执行脚本失败", runRequest.getReportId(), ex);
|
||||
return null;
|
||||
RemakeReportService remakeReportService = CommonBeanFactory.getBean(RemakeReportService.class);
|
||||
remakeReportService.testEnded(runRequest, ex.getMessage());
|
||||
}
|
||||
|
||||
LogUtil.info(testPlan.getJmx(jmeterHashTree));
|
||||
return jmeterHashTree;
|
||||
}
|
||||
|
||||
public static void remakeException(JmeterRunRequestDTO runRequest, Exception e) {
|
||||
RemakeReportService remakeReportService = CommonBeanFactory.getBean(RemakeReportService.class);
|
||||
remakeReportService.testEnded(runRequest, e.getMessage());
|
||||
ResultDTO dto = new ResultDTO();
|
||||
BeanUtils.copyBean(dto, runRequest);
|
||||
CommonBeanFactory.getBean(ApiExecutionQueueService.class).queueNext(dto);
|
||||
}
|
||||
|
||||
public static boolean isSetReport(RunModeConfigDTO config) {
|
||||
return config != null && isSetReport(config.getReportType()) && StringUtils.isNotEmpty(config.getReportName());
|
||||
}
|
||||
|
|
|
@ -1,15 +1,11 @@
|
|||
package io.metersphere.commons.utils;
|
||||
|
||||
import io.metersphere.service.ApiExecutionQueueService;
|
||||
import io.metersphere.service.RemakeReportService;
|
||||
import io.metersphere.base.domain.ApiExecutionQueue;
|
||||
import io.metersphere.base.domain.ApiExecutionQueueDetail;
|
||||
import io.metersphere.constants.RunModeConstants;
|
||||
import io.metersphere.dto.BaseSystemConfigDTO;
|
||||
import io.metersphere.dto.JmeterRunRequestDTO;
|
||||
import io.metersphere.dto.ResultDTO;
|
||||
import io.metersphere.service.SystemParameterService;
|
||||
import io.metersphere.utils.LoggerUtil;
|
||||
|
||||
public class RequestParamsUtil {
|
||||
|
||||
|
@ -28,13 +24,4 @@ public class RequestParamsUtil {
|
|||
runRequest.setPlatformUrl(GenerateHashTreeUtil.getPlatformUrl(baseInfo, runRequest, queue.getId()));
|
||||
return runRequest;
|
||||
}
|
||||
|
||||
public static void rollback(JmeterRunRequestDTO runRequest, Exception e) {
|
||||
RemakeReportService remakeReportService = CommonBeanFactory.getBean(RemakeReportService.class);
|
||||
remakeReportService.testEnded(runRequest, e.getMessage());
|
||||
ResultDTO dto = new ResultDTO();
|
||||
BeanUtils.copyBean(dto, runRequest);
|
||||
CommonBeanFactory.getBean(ApiExecutionQueueService.class).queueNext(dto);
|
||||
LoggerUtil.error("执行队列[" + runRequest.getQueueId() + "]入队列失败:", runRequest.getReportId(), e);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -138,6 +138,7 @@ public class ApiJMeterFileService {
|
|||
if (detail != null) {
|
||||
runRequest.setRetryEnable(detail.getRetryEnable());
|
||||
runRequest.setRetryNum(detail.getRetryNumber());
|
||||
runRequest.setRunType(detail.getType());
|
||||
}
|
||||
Map<String, String> processEnvMap = new LinkedHashMap<>();
|
||||
if (detail != null && StringUtils.isNotEmpty(detail.getEvnMap())) {
|
||||
|
@ -165,7 +166,6 @@ public class ApiJMeterFileService {
|
|||
} catch (Exception e) {
|
||||
remakeReportService.testEnded(runRequest, "生成执行脚本异常:" + e.getMessage());
|
||||
}
|
||||
remakeReportService.testEnded(runRequest, "未找到测试资源【" + remoteTestId + "】,资源类型:" + runMode);
|
||||
return new byte[0];
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue