fix(接口测试): 接口前置等待时间失效
This commit is contained in:
parent
077dace59f
commit
74fb26bd1d
|
@ -1,8 +1,7 @@
|
|||
package io.metersphere.api.parser.jmeter;
|
||||
|
||||
import io.metersphere.api.dto.request.controller.MsConstantTimerController;
|
||||
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.plugin.api.dto.ParameterConfig;
|
||||
import io.metersphere.plugin.api.spi.AbstractJmeterElementConverter;
|
||||
import io.metersphere.project.api.processor.TimeWaitingProcessor;
|
||||
|
@ -19,8 +18,7 @@ public class MsConstantTimerControllerConverter extends AbstractJmeterElementCon
|
|||
LogUtils.info("MsConstantTimerController is disabled");
|
||||
return;
|
||||
}
|
||||
MsProcessorConverter timeWaitingConverter = MsProcessorConverterFactory.getPostConverter(TimeWaitingProcessor.class);
|
||||
TimeWaitingProcessor timeWaitingProcessor = BeanUtils.copyBean(new TimeWaitingProcessor(), element);
|
||||
timeWaitingConverter.parse(tree, timeWaitingProcessor, config);
|
||||
new ScenarioTimeWaitingProcessorConverter().parse(tree, timeWaitingProcessor, config);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ 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.TimeWaitingProcessorConverter;
|
||||
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;
|
||||
|
@ -30,7 +30,6 @@ import org.apache.jmeter.config.Arguments;
|
|||
import org.apache.jmeter.protocol.http.control.CookieManager;
|
||||
import org.apache.jmeter.save.SaveService;
|
||||
import org.apache.jmeter.testelement.TestElement;
|
||||
import org.apache.jmeter.timers.ConstantTimer;
|
||||
import org.apache.jorphan.collections.HashTree;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -63,7 +62,7 @@ public class MsScenarioConverter extends AbstractJmeterElementConverter<MsScenar
|
|||
addArguments(tree, msScenario, envInfo);
|
||||
|
||||
// 添加场景每个步骤的全局等待时间
|
||||
addScenarioStepTimeWaiting(tree, msScenario);
|
||||
addScenarioStepTimeWaiting(tree, msScenario, msParameter);
|
||||
|
||||
// 添加环境的前置
|
||||
addEnvScenarioProcessor(tree, msScenario, config, envInfo, true);
|
||||
|
@ -88,7 +87,7 @@ public class MsScenarioConverter extends AbstractJmeterElementConverter<MsScenar
|
|||
* @param tree
|
||||
* @param msScenario
|
||||
*/
|
||||
private void addScenarioStepTimeWaiting(HashTree tree, MsScenario msScenario) {
|
||||
private void addScenarioStepTimeWaiting(HashTree tree, MsScenario msScenario, ParameterConfig config) {
|
||||
if (isRootScenario(msScenario.getRefType())) {
|
||||
// 获取场景前后置
|
||||
ScenarioConfig scenarioConfig = msScenario.getScenarioConfig();
|
||||
|
@ -97,8 +96,8 @@ public class MsScenarioConverter extends AbstractJmeterElementConverter<MsScenar
|
|||
TimeWaitingProcessor timeWaitingProcessor = new TimeWaitingProcessor();
|
||||
timeWaitingProcessor.setDelay(otherConfig.getStepWaitTime());
|
||||
timeWaitingProcessor.setName(msScenario.getName());
|
||||
ConstantTimer constantTimer = TimeWaitingProcessorConverter.getConstantTimer(timeWaitingProcessor);
|
||||
tree.add(constantTimer);
|
||||
MsProcessorConverter timeWaitingConverter = MsProcessorConverterFactory.getPreConverter(TimeWaitingProcessor.class);
|
||||
timeWaitingConverter.parse(tree, timeWaitingProcessor, config);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -283,7 +282,14 @@ public class MsScenarioConverter extends AbstractJmeterElementConverter<MsScenar
|
|||
// 添加场景前置处理器
|
||||
scenarioPreProcessors.forEach(processor -> {
|
||||
processor.setProjectId(msScenario.getProjectId());
|
||||
getConverterFunc.apply(processor.getClass()).parse(tree, processor, config);
|
||||
MsProcessorConverter converter;
|
||||
if (processor instanceof TimeWaitingProcessor) {
|
||||
// 场景的的等待时间,需要包一层 debugSampler
|
||||
converter = new ScenarioTimeWaitingProcessorConverter();
|
||||
} else {
|
||||
converter = getConverterFunc.apply(processor.getClass());
|
||||
}
|
||||
converter.parse(tree, processor, config);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
package io.metersphere.api.parser.jmeter.processor;
|
||||
|
||||
import io.metersphere.api.parser.jmeter.constants.JmeterAlias;
|
||||
import io.metersphere.plugin.api.constants.ElementProperty;
|
||||
import io.metersphere.plugin.api.dto.ParameterConfig;
|
||||
import io.metersphere.project.api.processor.TimeWaitingProcessor;
|
||||
import org.apache.jmeter.sampler.DebugSampler;
|
||||
import org.apache.jmeter.save.SaveService;
|
||||
import org.apache.jmeter.testelement.TestElement;
|
||||
import org.apache.jorphan.collections.HashTree;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* 场景的的等待时间,需要包一层 debugSampler
|
||||
* @Author: jianxing
|
||||
* @CreateTime: 2023-12-26 14:49
|
||||
*/
|
||||
public class ScenarioTimeWaitingProcessorConverter extends TimeWaitingProcessorConverter {
|
||||
@Override
|
||||
public void parse(HashTree hashTree, TimeWaitingProcessor processor, ParameterConfig config) {
|
||||
hashTree.add(getConstantTimerDebugSampler(), getConstantTimer(processor));
|
||||
}
|
||||
|
||||
private DebugSampler getConstantTimerDebugSampler() {
|
||||
// 添加 debugSampler 步骤间生效
|
||||
DebugSampler debugSampler = new DebugSampler();
|
||||
debugSampler.setEnabled(true);
|
||||
debugSampler.setName(ElementProperty.SCENARIO_CONSTANT_TIMER.name());
|
||||
debugSampler.setProperty(TestElement.TEST_CLASS, DebugSampler.class.getName());
|
||||
debugSampler.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass(JmeterAlias.TEST_BEAN_GUI));
|
||||
|
||||
// 下面三行直接Set属性会导致DebugSampler构建时取不到值,可能是JMeter的Bug,需要SetProperty
|
||||
debugSampler.setProperty("displayJMeterProperties", false);
|
||||
debugSampler.setProperty("displayJMeterVariables", false);
|
||||
debugSampler.setProperty("displaySystemProperties", false);
|
||||
|
||||
return debugSampler;
|
||||
}
|
||||
}
|
|
@ -1,11 +1,8 @@
|
|||
package io.metersphere.api.parser.jmeter.processor;
|
||||
|
||||
import io.metersphere.api.parser.jmeter.constants.JmeterAlias;
|
||||
import io.metersphere.plugin.api.constants.ElementProperty;
|
||||
import io.metersphere.plugin.api.dto.ParameterConfig;
|
||||
import io.metersphere.project.api.processor.TimeWaitingProcessor;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.jmeter.sampler.DebugSampler;
|
||||
import org.apache.jmeter.save.SaveService;
|
||||
import org.apache.jmeter.testelement.TestElement;
|
||||
import org.apache.jmeter.timers.ConstantTimer;
|
||||
|
@ -21,23 +18,7 @@ import static io.metersphere.api.parser.jmeter.constants.JmeterAlias.CONSTANT_TI
|
|||
public class TimeWaitingProcessorConverter extends MsProcessorConverter<TimeWaitingProcessor> {
|
||||
@Override
|
||||
public void parse(HashTree hashTree, TimeWaitingProcessor processor, ParameterConfig config) {
|
||||
hashTree.add(getConstantTimerElement(),getConstantTimer(processor));
|
||||
}
|
||||
|
||||
private DebugSampler getConstantTimerElement() {
|
||||
// 添加 debugSampler 步骤间生效
|
||||
DebugSampler debugSampler = new DebugSampler();
|
||||
debugSampler.setEnabled(true);
|
||||
debugSampler.setName(ElementProperty.SCENARIO_CONSTANT_TIMER.name());
|
||||
debugSampler.setProperty(TestElement.TEST_CLASS, DebugSampler.class.getName());
|
||||
debugSampler.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass(JmeterAlias.TEST_BEAN_GUI));
|
||||
|
||||
// 下面三行直接Set属性会导致DebugSampler构建时取不到值,可能是JMeter的Bug,需要SetProperty
|
||||
debugSampler.setProperty("displayJMeterProperties", false);
|
||||
debugSampler.setProperty("displayJMeterVariables", false);
|
||||
debugSampler.setProperty("displaySystemProperties", false);
|
||||
|
||||
return debugSampler;
|
||||
hashTree.add(getConstantTimer(processor));
|
||||
}
|
||||
|
||||
public static ConstantTimer getConstantTimer(TimeWaitingProcessor processor) {
|
||||
|
|
Loading…
Reference in New Issue