fix(接口测试): 修复CASE重试结果存储问题
--bug=1014528 --user=赵勇 【测试跟踪】测试计划选择失败重试n次,执行此接口用例后,会显示n个stop状态 https://www.tapd.cn/55049933/s/1194283
This commit is contained in:
parent
994e30e9d5
commit
d008f6f40a
|
@ -1,5 +1,5 @@
|
|||
package io.metersphere.api.exec.api;
|
||||
|
||||
public interface ApiRetryOnFailureService {
|
||||
public String retry(String data, long retryNum);
|
||||
public String retry(String data, long retryNum, boolean isCase);
|
||||
}
|
||||
|
|
|
@ -35,6 +35,7 @@ import io.metersphere.dto.ResultDTO;
|
|||
import io.metersphere.plugin.core.MsTestElement;
|
||||
import io.metersphere.service.SystemParameterService;
|
||||
import io.metersphere.utils.LoggerUtil;
|
||||
import io.metersphere.xpack.api.dto.MsRetryLoopController;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.jorphan.collections.HashTree;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
|
@ -138,6 +139,7 @@ public class ApiScenarioSerialService {
|
|||
SmoothWeighted.setServerConfig(runRequest.getPoolId(), redisTemplate);
|
||||
}
|
||||
// 开始执行
|
||||
LoggerUtil.info(new MsTestPlan().getJmx(runRequest.getHashTree()));
|
||||
jMeterService.run(runRequest);
|
||||
} catch (Exception e) {
|
||||
RemakeReportService remakeReportService = CommonBeanFactory.getBean(RemakeReportService.class);
|
||||
|
@ -202,7 +204,7 @@ public class ApiScenarioSerialService {
|
|||
// 失败重试
|
||||
if (runRequest.isRetryEnable() && runRequest.getRetryNum() > 0) {
|
||||
ApiRetryOnFailureService apiRetryOnFailureService = CommonBeanFactory.getBean(ApiRetryOnFailureService.class);
|
||||
String retryData = apiRetryOnFailureService.retry(data, runRequest.getRetryNum());
|
||||
String retryData = apiRetryOnFailureService.retry(data, runRequest.getRetryNum(), true);
|
||||
data = StringUtils.isNotEmpty(retryData) ? retryData : data;
|
||||
}
|
||||
|
||||
|
@ -214,8 +216,18 @@ public class ApiScenarioSerialService {
|
|||
group.setLabel(caseWithBLOBs.getName());
|
||||
group.setName(runRequest.getReportId());
|
||||
group.setProjectId(caseWithBLOBs.getProjectId());
|
||||
|
||||
MsTestElement testElement = parse(data, testId, envId, caseWithBLOBs.getProjectId());
|
||||
MsTestElement testElement = null;
|
||||
if (runRequest.isRetryEnable() && runRequest.getRetryNum() > 0) {
|
||||
MsRetryLoopController controller = JSON.parseObject(data, MsRetryLoopController.class);
|
||||
GenerateHashTreeUtil.parse(data, controller);
|
||||
MsTestElement element = parse(JSON.toJSONString(controller.getHashTree().get(0)), testId, envId, caseWithBLOBs.getProjectId());
|
||||
controller.setHashTree(new LinkedList<>() {{
|
||||
this.add(element);
|
||||
}});
|
||||
testElement = controller;
|
||||
} else {
|
||||
testElement = parse(data, testId, envId, caseWithBLOBs.getProjectId());
|
||||
}
|
||||
group.setHashTree(new LinkedList<>());
|
||||
group.getHashTree().add(testElement);
|
||||
testPlan.getHashTree().add(group);
|
||||
|
|
|
@ -27,6 +27,7 @@ import io.metersphere.plugin.core.MsTestElement;
|
|||
import io.metersphere.service.EnvironmentGroupProjectService;
|
||||
import io.metersphere.utils.LoggerUtil;
|
||||
import io.metersphere.vo.BooleanPool;
|
||||
import io.metersphere.xpack.api.dto.MsRetryLoopController;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.jorphan.collections.HashTree;
|
||||
|
||||
|
@ -71,6 +72,23 @@ public class GenerateHashTreeUtil {
|
|||
}
|
||||
}
|
||||
|
||||
public static void parse(String retryCase, MsRetryLoopController retryObj) {
|
||||
try {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
JSONObject element = JSON.parseObject(retryCase, Feature.DisableSpecialKeyDetect);
|
||||
ElementUtil.dataFormatting(element);
|
||||
if (element != null && StringUtils.isNotEmpty(element.getString("hashTree"))) {
|
||||
LinkedList<MsTestElement> elements = mapper.readValue(element.getString("hashTree"),
|
||||
new TypeReference<LinkedList<MsTestElement>>() {
|
||||
});
|
||||
retryObj.setHashTree(elements);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LogUtil.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static LinkedList<MsTestElement> getScenarioHashTree(String definition) {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
|
@ -139,7 +157,7 @@ public class GenerateHashTreeUtil {
|
|||
// 失败重试
|
||||
if (runRequest.isRetryEnable() && runRequest.getRetryNum() > 0) {
|
||||
ApiRetryOnFailureService apiRetryOnFailureService = CommonBeanFactory.getBean(ApiRetryOnFailureService.class);
|
||||
String retryData = apiRetryOnFailureService.retry(data, runRequest.getRetryNum());
|
||||
String retryData = apiRetryOnFailureService.retry(data, runRequest.getRetryNum(), false);
|
||||
data = StringUtils.isNotEmpty(retryData) ? retryData : data;
|
||||
}
|
||||
|
||||
|
|
|
@ -35,21 +35,21 @@ public class APISingleResultListener implements MsExecListener {
|
|||
@Override
|
||||
public void handleTeardownTest(List<SampleResult> results, ResultDTO dto, Map<String, Object> kafkaConfig) {
|
||||
LoggerUtil.info("接收到执行结果开始处理报告【" + dto.getReportId() + " 】,资源【 " + dto.getTestId() + " 】");
|
||||
// 清理过程步骤
|
||||
results = RetryResultUtil.clearLoops(results);
|
||||
queues.addAll(results);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void testEnded(ResultDTO dto, Map<String, Object> kafkaConfig) {
|
||||
try {
|
||||
// 清理过程步骤
|
||||
queues = RetryResultUtil.clearLoops(queues);
|
||||
JMeterBase.resultFormatting(queues, dto);
|
||||
if (dto.isRetryEnable()) {
|
||||
LoggerUtil.info("重试结果处理【" + dto.getReportId() + " 】开始");
|
||||
RetryResultUtil.mergeRetryResults(queues);
|
||||
RetryResultUtil.mergeRetryResults(dto.getRequestResults());
|
||||
LoggerUtil.info("重试结果处理【" + dto.getReportId() + " 】结束");
|
||||
}
|
||||
|
||||
JMeterBase.resultFormatting(queues, dto);
|
||||
dto.setConsole(FixedCapacityUtils.getJmeterLogger(dto.getReportId(), !StringUtils.equals(dto.getReportType(), RunModeConstants.SET_REPORT.toString())));
|
||||
// 入库存储
|
||||
CommonBeanFactory.getBean(TestResultService.class).saveResults(dto);
|
||||
|
|
Loading…
Reference in New Issue