refactor(接口测试): 场景变量当所有优先规则不选时,默认过程变量优先并兼容历史数据
--bug=1022046 --user=赵勇 【接口测试】github#21416,1.10.11 升级1.20.18 ,接口自动化a场景引用b场景 修改b场景里面的场景变量保存后,a场景调试 刚刚修改的变量不生效 https://www.tapd.cn/55049933/s/1329562
This commit is contained in:
parent
c4aa85a358
commit
430784015f
|
@ -966,4 +966,38 @@ public class ElementUtil {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 过程变量覆盖处理
|
||||
*
|
||||
* @param tree
|
||||
*/
|
||||
public static void coverArguments(HashTree tree) {
|
||||
Map<String, String> process = new HashMap<>();
|
||||
coverArguments(tree, process);
|
||||
}
|
||||
|
||||
public static void coverArguments(HashTree tree, Map<String, String> process) {
|
||||
for (Object key : tree.keySet()) {
|
||||
HashTree node = tree.get(key);
|
||||
if (key instanceof Arguments) {
|
||||
Arguments arguments = (Arguments) key;
|
||||
if (arguments.getProperty(ElementConstants.COVER) == null) {
|
||||
continue;
|
||||
}
|
||||
for (int i = 0; i < arguments.getArguments().size(); ++i) {
|
||||
String argKey = arguments.getArgument(i).getName();
|
||||
String argValue = arguments.getArgument(i).getValue();
|
||||
if (process.containsKey(argKey)) {
|
||||
arguments.getArgument(i).setValue(process.get(argKey));
|
||||
} else {
|
||||
process.put(argKey, argValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (node != null) {
|
||||
coverArguments(node, process);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -127,6 +127,7 @@ public class MsScenario extends MsTestElement {
|
|||
if (BooleanUtils.isTrue(this.variableEnable) || BooleanUtils.isTrue(this.mixEnable)) {
|
||||
scenarioTree.add(ElementUtil.argumentsToUserParameters(valueSupposeMock));
|
||||
} else if (config != null && (this.isAllEnable() || config.isApi())) {
|
||||
valueSupposeMock.setProperty(ElementConstants.COVER, true);
|
||||
scenarioTree.add(valueSupposeMock);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package io.metersphere.api.exec.engine;
|
|||
import io.fabric8.kubernetes.api.model.Pod;
|
||||
import io.fabric8.kubernetes.client.KubernetesClient;
|
||||
import io.metersphere.api.dto.MsgDTO;
|
||||
import io.metersphere.api.dto.definition.request.ElementUtil;
|
||||
import io.metersphere.base.domain.TestResource;
|
||||
import io.metersphere.commons.constants.ApiRunMode;
|
||||
import io.metersphere.commons.constants.ExtendedParameter;
|
||||
|
@ -24,6 +25,8 @@ import java.util.Set;
|
|||
public class KubernetesTestEngine extends AbstractEngine {
|
||||
private JmeterRunRequestDTO runRequest;
|
||||
private final String DEBUG_ERROR = "DEBUG_ERROR";
|
||||
private final String EXEC_URL = "api/start";
|
||||
private final String DEBUG_URL = "debug";
|
||||
|
||||
// 初始化API调用
|
||||
public KubernetesTestEngine(JmeterRunRequestDTO runRequest) {
|
||||
|
@ -60,9 +63,9 @@ public class KubernetesTestEngine extends AbstractEngine {
|
|||
.append(StringUtils.LF).append("Pod信息:【 ")
|
||||
.append(JSON.toJSONString(pod.getMetadata())).append(" 】");
|
||||
LoggerUtil.info(logMsg);
|
||||
String path = "api/start";
|
||||
if (runRequest.getHashTree() != null) {
|
||||
path = "debug";
|
||||
boolean isDebug = runRequest.getHashTree() != null;
|
||||
if (isDebug) {
|
||||
ElementUtil.coverArguments(runRequest.getHashTree());
|
||||
if (runRequest.isDebug() && !StringUtils.equalsAny(runRequest.getRunMode(), ApiRunMode.DEFINITION.name())) {
|
||||
runRequest.getExtendedParameters().put(ExtendedParameter.SAVE_RESULT, true);
|
||||
} else if (!runRequest.isDebug()) {
|
||||
|
@ -77,7 +80,7 @@ public class KubernetesTestEngine extends AbstractEngine {
|
|||
command.append(StringUtils.SPACE).append("--connect-timeout 30"); // 设置连接超时时间为30S
|
||||
command.append(StringUtils.SPACE).append("--max-time 120"); // 设置请求超时时间为120S
|
||||
command.append(StringUtils.SPACE).append("--retry 3"); // 设置重试次数3次
|
||||
command.append(StringUtils.SPACE).append("http://127.0.0.1:8082/jmeter/").append(path);
|
||||
command.append(StringUtils.SPACE).append("http://127.0.0.1:8082/jmeter/").append(isDebug ? DEBUG_URL : EXEC_URL);
|
||||
KubernetesApiExec.newExecWatch(client, clientCredential.getNamespace(), pod.getMetadata().getName(), command.toString());
|
||||
} catch (Exception e) {
|
||||
MsgDTO dto = new MsgDTO();
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package io.metersphere.api.jmeter;
|
||||
|
||||
|
||||
import io.metersphere.api.dto.definition.request.ElementUtil;
|
||||
import io.metersphere.api.dto.definition.request.MsTestPlan;
|
||||
import io.metersphere.api.exec.engine.EngineFactory;
|
||||
import io.metersphere.api.exec.queue.ExecThreadPoolExecutor;
|
||||
|
@ -149,6 +150,7 @@ public class JMeterService {
|
|||
try {
|
||||
// 缓存调试脚本
|
||||
if (request.getHashTree() != null) {
|
||||
ElementUtil.coverArguments(request.getHashTree());
|
||||
String key = StringUtils.join(request.getReportId(), "-", request.getTestId());
|
||||
redisTemplate.opsForValue().set(key, new MsTestPlan().getJmx(request.getHashTree()));
|
||||
}
|
||||
|
@ -177,6 +179,7 @@ public class JMeterService {
|
|||
if (apiPoolDebugService != null) {
|
||||
List<TestResource> resources = GenerateHashTreeUtil.setPoolResource(request.getPoolId());
|
||||
if (request.getHashTree() != null) {
|
||||
ElementUtil.coverArguments(request.getHashTree());
|
||||
String key = StringUtils.join(request.getReportId(), "-", request.getTestId());
|
||||
redisTemplate.opsForValue().set(key, new MsTestPlan().getJmx(request.getHashTree()));
|
||||
request.setHashTree(null);
|
||||
|
@ -228,6 +231,7 @@ public class JMeterService {
|
|||
if (request.getPool().isPool() && StringUtils.isNotBlank(request.getRunMode())) {
|
||||
this.runNode(request);
|
||||
} else if (request.getHashTree() != null) {
|
||||
ElementUtil.coverArguments(request.getHashTree());
|
||||
//解析hashTree,是否含有文件库文件
|
||||
HashTreeUtil.initRepositoryFiles(request);
|
||||
execThreadPoolExecutor.addTask(request);
|
||||
|
|
|
@ -56,4 +56,5 @@ public class ElementConstants {
|
|||
public static final String FILE_ID = "fileId";
|
||||
public static final String RESOURCE_ID = "resourceId";
|
||||
public static final String FILENAME = "filename";
|
||||
public static final String COVER = "COVER";
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package io.metersphere.service;
|
|||
|
||||
import io.metersphere.api.dto.BodyFileRequest;
|
||||
import io.metersphere.api.dto.EnvironmentType;
|
||||
import io.metersphere.api.dto.definition.request.ElementUtil;
|
||||
import io.metersphere.api.dto.definition.request.MsTestPlan;
|
||||
import io.metersphere.api.exec.api.ApiCaseSerialService;
|
||||
import io.metersphere.base.domain.*;
|
||||
|
@ -126,6 +127,9 @@ public class ApiJMeterFileService {
|
|||
}
|
||||
hashTree = GenerateHashTreeUtil.generateHashTree(scenario, planEnvMap, runRequest);
|
||||
}
|
||||
if (hashTree != null) {
|
||||
ElementUtil.coverArguments(hashTree);
|
||||
}
|
||||
return zipFilesToByteArray((reportId + "_" + remoteTestId), hashTree);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue