fix(接口测试): 修复循环控制器中遍历CSV隔行取值问题

This commit is contained in:
fit2-zhao 2022-05-31 17:30:24 +08:00 committed by f2c-ci-robot[bot]
parent cf5b10ea5e
commit f0cfa5fb84
3 changed files with 26 additions and 5 deletions

View File

@ -127,7 +127,7 @@ public class MsScenario extends MsTestElement {
} }
} }
} }
if (CollectionUtils.isNotEmpty(this.getVariables())) { if (CollectionUtils.isNotEmpty(this.getVariables()) && (this.variableEnable == null || this.variableEnable)) {
config.setVariables(this.variables); config.setVariables(this.variables);
} }
HashTree scenarioTree = tree; HashTree scenarioTree = tree;

View File

@ -7,6 +7,7 @@ import io.metersphere.api.dto.definition.request.ParameterConfig;
import io.metersphere.api.dto.definition.request.controller.loop.CountController; import io.metersphere.api.dto.definition.request.controller.loop.CountController;
import io.metersphere.api.dto.definition.request.controller.loop.MsForEachController; import io.metersphere.api.dto.definition.request.controller.loop.MsForEachController;
import io.metersphere.api.dto.definition.request.controller.loop.MsWhileController; import io.metersphere.api.dto.definition.request.controller.loop.MsWhileController;
import io.metersphere.api.dto.definition.request.variable.ScenarioVariable;
import io.metersphere.api.dto.shell.filter.ScriptFilter; import io.metersphere.api.dto.shell.filter.ScriptFilter;
import io.metersphere.commons.constants.LoopConstants; import io.metersphere.commons.constants.LoopConstants;
import io.metersphere.plugin.core.MsParameter; import io.metersphere.plugin.core.MsParameter;
@ -25,8 +26,11 @@ import org.apache.jmeter.testelement.TestElement;
import org.apache.jmeter.timers.ConstantTimer; import org.apache.jmeter.timers.ConstantTimer;
import org.apache.jorphan.collections.HashTree; import org.apache.jorphan.collections.HashTree;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.UUID; import java.util.UUID;
import java.util.stream.Collectors;
@Data @Data
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
@ -67,9 +71,24 @@ public class MsLoopController extends MsTestElement {
} }
// 当前引用场景 // 当前引用场景
if (CollectionUtils.isNotEmpty(config.getTransferVariables())) { if (CollectionUtils.isNotEmpty(config.getTransferVariables())) {
ElementUtil.addCsvDataSet(groupTree, config.getTransferVariables(), config, "shareMode.thread"); final List<ScenarioVariable> variables = new LinkedList<>();
ElementUtil.addCounter(groupTree, config.getTransferVariables(), true); if (CollectionUtils.isEmpty(config.getVariables())) {
ElementUtil.addRandom(groupTree, config.getTransferVariables()); variables.addAll(config.getTransferVariables());
} else {
// 合并处理
Map<String, ScenarioVariable> variableMap = config.getVariables().stream().collect(Collectors.toMap(ScenarioVariable::getId, a -> a, (k1, k2) -> k1));
config.getTransferVariables().forEach(item -> {
if (!variableMap.containsKey(item.getId())) {
variables.add(item);
}
});
}
if (CollectionUtils.isNotEmpty(variables)) {
ElementUtil.addCsvDataSet(groupTree, variables, config, "shareMode.thread");
ElementUtil.addCounter(groupTree, variables, true);
ElementUtil.addRandom(groupTree, variables);
}
} }
// 循环下都增加一个计数器用于结果统计 // 循环下都增加一个计数器用于结果统计
groupTree.add(addCounterConfig()); groupTree.add(addCounterConfig());

View File

@ -7,6 +7,7 @@ import io.metersphere.api.dto.automation.APIScenarioReportResult;
import io.metersphere.api.dto.automation.ExecuteType; import io.metersphere.api.dto.automation.ExecuteType;
import io.metersphere.api.dto.automation.RunScenarioRequest; import io.metersphere.api.dto.automation.RunScenarioRequest;
import io.metersphere.api.dto.definition.RunDefinitionRequest; import io.metersphere.api.dto.definition.RunDefinitionRequest;
import io.metersphere.api.dto.definition.request.MsTestPlan;
import io.metersphere.api.dto.definition.request.ParameterConfig; import io.metersphere.api.dto.definition.request.ParameterConfig;
import io.metersphere.api.exec.queue.DBTestQueue; import io.metersphere.api.exec.queue.DBTestQueue;
import io.metersphere.api.exec.utils.GenerateHashTreeUtil; import io.metersphere.api.exec.utils.GenerateHashTreeUtil;
@ -176,7 +177,7 @@ public class ApiScenarioExecuteService {
String finalSerialReportId = serialReportId; String finalSerialReportId = serialReportId;
Thread thread = new Thread(() -> Thread thread = new Thread(() ->
{ {
Thread.currentThread().setName("SCENARIO-PARALLEL-THREAD"); Thread.currentThread().setName("SCENARIO-THREAD");
if (isSerial(request)) { if (isSerial(request)) {
apiScenarioSerialService.serial(executionQueue, executionQueue.getQueue()); apiScenarioSerialService.serial(executionQueue, executionQueue.getQueue());
} else { } else {
@ -398,6 +399,7 @@ public class ApiScenarioExecuteService {
String runMode = StringUtils.isEmpty(request.getRunMode()) ? ApiRunMode.SCENARIO.name() : request.getRunMode(); String runMode = StringUtils.isEmpty(request.getRunMode()) ? ApiRunMode.SCENARIO.name() : request.getRunMode();
// 调用执行方法 // 调用执行方法
JmeterRunRequestDTO runRequest = new JmeterRunRequestDTO(request.getId(), request.getId(), runMode, hashTree); JmeterRunRequestDTO runRequest = new JmeterRunRequestDTO(request.getId(), request.getId(), runMode, hashTree);
LoggerUtil.info(new MsTestPlan().getJmx(hashTree));
runRequest.setDebug(true); runRequest.setDebug(true);
jMeterService.run(runRequest); jMeterService.run(runRequest);
return request.getId(); return request.getId();