fix(接口测试): 优化场景前置等待时间配置
This commit is contained in:
parent
7a1f17c22e
commit
8acefab96d
|
@ -20,11 +20,6 @@ public class ScenarioOtherConfig {
|
|||
* 启用场景步骤等待时间
|
||||
*/
|
||||
private Boolean enableStepWait = false;
|
||||
/**
|
||||
* 场景步骤等待时间
|
||||
* 每一个步骤执行后都会等待相应的时间
|
||||
*/
|
||||
private Long stepWaitTime;
|
||||
/**
|
||||
* 失败策略
|
||||
* @see FailureStrategy
|
||||
|
|
|
@ -7,8 +7,11 @@ import io.metersphere.api.dto.debug.ApiResourceRunRequest;
|
|||
import io.metersphere.api.dto.request.MsScenario;
|
||||
import io.metersphere.api.dto.scenario.ApiScenarioDetail;
|
||||
import io.metersphere.api.dto.scenario.ApiScenarioParseParam;
|
||||
import io.metersphere.api.dto.scenario.ScenarioConfig;
|
||||
import io.metersphere.api.service.ApiExecuteService;
|
||||
import io.metersphere.api.service.scenario.ApiScenarioService;
|
||||
import io.metersphere.project.api.processor.MsProcessor;
|
||||
import io.metersphere.project.api.processor.TimeWaitingProcessor;
|
||||
import io.metersphere.sdk.constants.ApiBatchRunMode;
|
||||
import io.metersphere.sdk.constants.ApiExecuteRunMode;
|
||||
import io.metersphere.sdk.constants.TaskTriggerMode;
|
||||
|
@ -22,10 +25,14 @@ import io.metersphere.system.uid.IDGenerator;
|
|||
import org.apache.commons.lang3.BooleanUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.quartz.JobExecutionContext;
|
||||
import org.quartz.JobKey;
|
||||
import org.quartz.TriggerKey;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
public class ApiScenarioScheduleJob extends BaseScheduleJob {
|
||||
@Override
|
||||
protected void businessExecute(JobExecutionContext context) {
|
||||
|
@ -74,11 +81,8 @@ public class ApiScenarioScheduleJob extends BaseScheduleJob {
|
|||
scenarioReport.setRunMode(ApiBatchRunMode.PARALLEL.name());
|
||||
scenarioReport.setPoolId(apiRunModeConfigDTO.getPoolId());
|
||||
scenarioReport.setEnvironmentId(parseParam.getEnvironmentId());
|
||||
if (parseParam.getScenarioConfig() != null
|
||||
&& parseParam.getScenarioConfig().getOtherConfig() != null
|
||||
&& BooleanUtils.isTrue(parseParam.getScenarioConfig().getOtherConfig().getEnableStepWait())) {
|
||||
scenarioReport.setWaitingTime(parseParam.getScenarioConfig().getOtherConfig().getStepWaitTime());
|
||||
}
|
||||
scenarioReport.setWaitingTime(apiScenarioService.getGlobalWaitTime(parseParam.getScenarioConfig()));
|
||||
|
||||
apiScenarioService.initApiReport(apiScenarioDetail, scenarioReport);
|
||||
|
||||
// 初始化报告步骤
|
||||
|
@ -87,6 +91,8 @@ public class ApiScenarioScheduleJob extends BaseScheduleJob {
|
|||
apiExecuteService.execute(runRequest, taskRequest, parseConfig);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static JobKey getJobKey(String scenarioId) {
|
||||
return new JobKey(scenarioId, ApiScenarioScheduleJob.class.getName());
|
||||
}
|
||||
|
|
|
@ -6,18 +6,15 @@ import io.metersphere.api.dto.ApiScenarioParamConfig;
|
|||
import io.metersphere.api.dto.request.MsScenario;
|
||||
import io.metersphere.api.dto.request.processors.MsProcessorConfig;
|
||||
import io.metersphere.api.dto.scenario.ScenarioConfig;
|
||||
import io.metersphere.api.dto.scenario.ScenarioOtherConfig;
|
||||
import io.metersphere.api.dto.scenario.ScenarioStepConfig;
|
||||
import io.metersphere.api.dto.scenario.ScenarioVariable;
|
||||
import io.metersphere.api.parser.jmeter.processor.MsProcessorConverter;
|
||||
import io.metersphere.api.parser.jmeter.processor.MsProcessorConverterFactory;
|
||||
import io.metersphere.api.parser.jmeter.processor.ScenarioTimeWaitingProcessorConverter;
|
||||
import io.metersphere.api.parser.jmeter.processor.assertion.AssertionConverterFactory;
|
||||
import io.metersphere.plugin.api.dto.ParameterConfig;
|
||||
import io.metersphere.plugin.api.spi.AbstractJmeterElementConverter;
|
||||
import io.metersphere.project.api.assertion.MsAssertion;
|
||||
import io.metersphere.project.api.processor.MsProcessor;
|
||||
import io.metersphere.project.api.processor.TimeWaitingProcessor;
|
||||
import io.metersphere.project.dto.environment.EnvironmentConfig;
|
||||
import io.metersphere.project.dto.environment.EnvironmentInfoDTO;
|
||||
import io.metersphere.project.dto.environment.processors.EnvProcessorConfig;
|
||||
|
@ -61,9 +58,6 @@ public class MsScenarioConverter extends AbstractJmeterElementConverter<MsScenar
|
|||
// 添加场景和环境变量
|
||||
addArguments(tree, msScenario, envInfo);
|
||||
|
||||
// 添加场景每个步骤的全局等待时间
|
||||
addScenarioStepTimeWaiting(tree, msScenario, msParameter);
|
||||
|
||||
// 添加环境的前置
|
||||
addEnvScenarioProcessor(tree, msScenario, config, envInfo, true);
|
||||
// 添加场景前置
|
||||
|
@ -82,26 +76,6 @@ public class MsScenarioConverter extends AbstractJmeterElementConverter<MsScenar
|
|||
addScenarioAssertions(tree, msScenario, config);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加步骤等待
|
||||
* @param tree
|
||||
* @param msScenario
|
||||
*/
|
||||
private void addScenarioStepTimeWaiting(HashTree tree, MsScenario msScenario, ParameterConfig config) {
|
||||
if (isRootScenario(msScenario.getRefType())) {
|
||||
// 获取场景前后置
|
||||
ScenarioConfig scenarioConfig = msScenario.getScenarioConfig();
|
||||
ScenarioOtherConfig otherConfig = scenarioConfig.getOtherConfig();
|
||||
if (BooleanUtils.isTrue(otherConfig.getEnableStepWait())) {
|
||||
TimeWaitingProcessor timeWaitingProcessor = new TimeWaitingProcessor();
|
||||
timeWaitingProcessor.setDelay(otherConfig.getStepWaitTime());
|
||||
timeWaitingProcessor.setName(msScenario.getName());
|
||||
MsProcessorConverter timeWaitingConverter = MsProcessorConverterFactory.getPreConverter(TimeWaitingProcessor.class);
|
||||
timeWaitingConverter.parse(tree, timeWaitingProcessor, config);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加场景和环境变量
|
||||
* @param tree
|
||||
|
@ -282,14 +256,7 @@ public class MsScenarioConverter extends AbstractJmeterElementConverter<MsScenar
|
|||
// 添加场景前置处理器
|
||||
scenarioPreProcessors.forEach(processor -> {
|
||||
processor.setProjectId(msScenario.getProjectId());
|
||||
MsProcessorConverter converter;
|
||||
if (processor instanceof TimeWaitingProcessor) {
|
||||
// 场景的的等待时间,需要包一层 debugSampler
|
||||
converter = new ScenarioTimeWaitingProcessorConverter();
|
||||
} else {
|
||||
converter = getConverterFunc.apply(processor.getClass());
|
||||
}
|
||||
converter.parse(tree, processor, config);
|
||||
getConverterFunc.apply(processor.getClass()).parse(tree, processor, config);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -348,12 +348,11 @@ public class ApiScenarioBatchRunService {
|
|||
}
|
||||
|
||||
private void updateReportWaitTime(String reportId, ApiScenarioParseParam parseParam) {
|
||||
if (parseParam.getScenarioConfig() != null
|
||||
&& parseParam.getScenarioConfig().getOtherConfig() != null
|
||||
&& BooleanUtils.isTrue(parseParam.getScenarioConfig().getOtherConfig().getEnableStepWait())) {
|
||||
Long globalWaitTime = apiScenarioService.getGlobalWaitTime(parseParam.getScenarioConfig());
|
||||
if (globalWaitTime != null) {
|
||||
ApiScenarioReport apiScenarioReport = new ApiScenarioReport();
|
||||
apiScenarioReport.setId(reportId);
|
||||
apiScenarioReport.setWaitingTime(parseParam.getScenarioConfig().getOtherConfig().getStepWaitTime());
|
||||
apiScenarioReport.setWaitingTime(globalWaitTime);
|
||||
apiScenarioReportMapper.updateByPrimaryKeySelective(apiScenarioReport);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,6 +27,8 @@ import io.metersphere.api.service.definition.ApiTestCaseService;
|
|||
import io.metersphere.api.utils.ApiDataUtils;
|
||||
import io.metersphere.api.utils.ApiScenarioBatchOperationUtils;
|
||||
import io.metersphere.plugin.api.spi.AbstractMsTestElement;
|
||||
import io.metersphere.project.api.processor.MsProcessor;
|
||||
import io.metersphere.project.api.processor.TimeWaitingProcessor;
|
||||
import io.metersphere.project.domain.FileAssociation;
|
||||
import io.metersphere.project.domain.FileMetadata;
|
||||
import io.metersphere.project.domain.Project;
|
||||
|
@ -1390,11 +1392,8 @@ public class ApiScenarioService extends MoveNodeService {
|
|||
scenarioReport.setRunMode(ApiBatchRunMode.PARALLEL.name());
|
||||
scenarioReport.setPoolId(poolId);
|
||||
scenarioReport.setEnvironmentId(parseParam.getEnvironmentId());
|
||||
if (parseParam.getScenarioConfig() != null
|
||||
&& parseParam.getScenarioConfig().getOtherConfig() != null
|
||||
&& BooleanUtils.isTrue(parseParam.getScenarioConfig().getOtherConfig().getEnableStepWait())) {
|
||||
scenarioReport.setWaitingTime(parseParam.getScenarioConfig().getOtherConfig().getStepWaitTime());
|
||||
}
|
||||
scenarioReport.setWaitingTime(getGlobalWaitTime(parseParam.getScenarioConfig()));
|
||||
|
||||
initApiReport(apiScenario, scenarioReport);
|
||||
|
||||
// 初始化报告步骤
|
||||
|
@ -2850,4 +2849,29 @@ public class ApiScenarioService extends MoveNodeService {
|
|||
apiStepResourceInfo.setProjectName(project.getName());
|
||||
return apiStepResourceInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取场景前置的总等待时间
|
||||
* @param scenarioConfig
|
||||
* @return
|
||||
*/
|
||||
public Long getGlobalWaitTime(ScenarioConfig scenarioConfig) {
|
||||
Long waitTime = null;
|
||||
if (scenarioConfig != null
|
||||
&& scenarioConfig.getPreProcessorConfig() != null
|
||||
&& scenarioConfig.getPreProcessorConfig().getProcessors() != null) {
|
||||
waitTime = 0L;
|
||||
for (MsProcessor processor : scenarioConfig
|
||||
.getPreProcessorConfig()
|
||||
.getProcessors()) {
|
||||
if (processor instanceof TimeWaitingProcessor timeWaitingProcessor
|
||||
&& timeWaitingProcessor.getEnable()
|
||||
&& timeWaitingProcessor.getDelay() != null) {
|
||||
waitTime += timeWaitingProcessor.getDelay();
|
||||
}
|
||||
}
|
||||
waitTime = waitTime > 0 ? waitTime : null;
|
||||
}
|
||||
return waitTime;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -456,7 +456,6 @@ public class ApiScenarioControllerTests extends BaseTest {
|
|||
responseCodeAssertion.setName("test");
|
||||
scenarioConfig.getAssertionConfig().getAssertions().add(responseCodeAssertion);
|
||||
ScenarioOtherConfig scenarioOtherConfig = new ScenarioOtherConfig();
|
||||
scenarioOtherConfig.setStepWaitTime(1000L);
|
||||
scenarioOtherConfig.setFailureStrategy(ScenarioOtherConfig.FailureStrategy.CONTINUE.name());
|
||||
scenarioOtherConfig.setEnableCookieShare(true);
|
||||
scenarioConfig.setOtherConfig(scenarioOtherConfig);
|
||||
|
|
Loading…
Reference in New Issue