fix(接口测试): 修复测试计划选择失败重试,循环控制器下的请求未执行完全的缺陷

--bug=1025334 --user=王孝刚
【测试跟踪】github#23509,测试计划执行时选择失败重试,导致计划中接口脚本的循环没有被执行完全。如果不选择失败重试则没有问题
https://www.tapd.cn/55049933/s/1361589
This commit is contained in:
wxg0103 2023-04-12 13:45:56 +08:00 committed by wxg0103
parent aec36b2613
commit b655dbf856
8 changed files with 33 additions and 7 deletions

View File

@ -1032,6 +1032,18 @@ public class ElementUtil {
return loopController.controller(tree, name);
}
public static boolean isLoop(MsTestElement sampler) {
if (sampler != null ) {
if (StringUtils.equals(sampler.getType(), "LoopController")) {
return true;
}
if (sampler.getParent() != null) {
return isLoop(sampler.getParent());
}
}
return false;
}
public static DatabaseConfig selectDataSourceFromJDBCProcessor(String processorName, String environmentId, String dataSourceId, String projectId, ParameterConfig config) {
if (config == null) {
return null;

View File

@ -60,7 +60,7 @@ public class MsJSR223Processor extends MsTestElement {
// 失败重试
HashTree jsr223PreTree;
if (config.getRetryNum() > 0) {
if (config.getRetryNum() > 0 && !ElementUtil.isLoop(this.getParent())) {
final HashTree loopTree = ElementUtil.retryHashTree(this.getName(), config.getRetryNum(), tree);
jsr223PreTree = loopTree.add(processor);
} else {

View File

@ -80,7 +80,7 @@ public class MsDubboSampler extends MsTestElement {
}
// 失败重试
HashTree testPlanTree;
if (config.getRetryNum() > 0) {
if (config.getRetryNum() > 0 && !ElementUtil.isLoop(this.getParent())) {
final HashTree loopTree = ElementUtil.retryHashTree(this.getName(), config.getRetryNum(), tree);
testPlanTree = loopTree.add(dubboSample(config));
} else {

View File

@ -169,7 +169,7 @@ public class MsHTTPSamplerProxy extends MsTestElement {
}
// 失败重试
HashTree httpSamplerTree;
if (config.getRetryNum() > 0) {
if (config.getRetryNum() > 0 && !ElementUtil.isLoop(this.getParent())) {
final HashTree loopTree = ElementUtil.retryHashTree(this.getName(), config.getRetryNum(), tree);
httpSamplerTree = loopTree.add(sampler);
} else {

View File

@ -122,7 +122,7 @@ public class MsJDBCSampler extends MsTestElement {
JDBCSampler jdbcSampler = jdbcSampler(config);
// 失败重试
HashTree samplerHashTree;
if (config.getRetryNum() > 0) {
if (config.getRetryNum() > 0 && !ElementUtil.isLoop(this.getParent())) {
final HashTree loopTree = ElementUtil.retryHashTree(this.getName(), config.getRetryNum(), tree);
samplerHashTree = loopTree.add(jdbcSampler);
} else {

View File

@ -141,7 +141,7 @@ public class MsTCPSampler extends MsTestElement {
samplerHashTree.add(tcpConfig());
TCPSampler tcpSampler = tcpSampler(config);
// 失败重试
if (config.getRetryNum() > 0) {
if (config.getRetryNum() > 0 && !ElementUtil.isLoop(this.getParent())) {
final HashTree loopTree = ElementUtil.retryHashTree(this.getName(), config.getRetryNum(), tree);
loopTree.set(tcpSampler, samplerHashTree);
} else {

View File

@ -3,6 +3,7 @@ package io.metersphere.api.parse.api;
import io.metersphere.api.dto.ApiTestImportRequest;
import io.metersphere.api.dto.definition.request.sampler.MsHTTPSamplerProxy;
import io.metersphere.api.dto.definition.response.HttpResponse;
import io.metersphere.api.parse.ApiImportAbstractParser;
import io.metersphere.api.parse.MsAbstractParser;
import io.metersphere.base.domain.ApiDefinitionWithBLOBs;
@ -111,6 +112,14 @@ public class MsDefinitionParser extends MsAbstractParser<ApiDefinitionImport> {
requestObj.put("url", StringUtils.EMPTY);
apiDefinition.setRequest(requestObj.toString());
}
JSONObject responseObject = new JSONObject();
try {
// 设置响应体
responseObject = JSONUtil.parseObject(apiDefinition.getResponse());
} catch (Exception e) {
responseObject = new JSONObject(new HttpResponse());
}
apiDefinition.setResponse(responseObject.toString());
apiDefinition.setCreateUser(SessionUtils.getUserId());
apiDefinition.setUserId(SessionUtils.getUserId());
apiDefinition.setDeleteUserId(null);

View File

@ -717,8 +717,13 @@ public class Swagger3Parser extends SwaggerAbstractParser {
JSONObject requestBody = buildRequestBody(requestObject, schemas);
swaggerApiInfo.setRequestBody(JSONUtil.parseObjectNode(requestBody.toString()));
// 设置响应体
JSONObject responseObject = JSONUtil.parseObject(apiDefinition.getResponse());
JSONObject responseObject = new JSONObject();
try {
// 设置响应体
responseObject = JSONUtil.parseObject(apiDefinition.getResponse());
} catch (Exception e) {
responseObject = new JSONObject(new ApiResponse());
}
JSONObject jsonObject = buildResponseBody(responseObject, schemas);
swaggerApiInfo.setResponses(JSONUtil.parseObjectNode(jsonObject.toString()));
// 设置请求参数列表