fix(接口测试): 修复用例引用关系错误问题
--bug=1023899 --user=赵勇 【接口测试】github#22259,场景用例嵌套,删除用例后查找引用错误 https://www.tapd.cn/55049933/s/1349232 Signed-off-by: fit2-zhao <yong.zhao@fit2cloud.com>
This commit is contained in:
parent
09ac00a06e
commit
bcbbd2563d
|
@ -117,10 +117,10 @@ public class JMeterService {
|
|||
// 接口用例集成报告/测试计划报告日志记录
|
||||
if (StringUtils.isNotEmpty(request.getTestPlanReportId())
|
||||
&& StringUtils.equals(request.getReportType(), RunModeConstants.SET_REPORT.toString())) {
|
||||
FixedCapacityUtil.put(request.getTestPlanReportId(), new StringBuffer(""));
|
||||
FixedCapacityUtil.put(request.getTestPlanReportId(), new StringBuffer());
|
||||
} else {
|
||||
// 报告日志记录
|
||||
FixedCapacityUtil.put(request.getReportId(), new StringBuffer(""));
|
||||
FixedCapacityUtil.put(request.getReportId(), new StringBuffer());
|
||||
}
|
||||
LoggerUtil.debug("监听MessageCache.tasks当前容量:" + FixedCapacityUtil.size());
|
||||
if (request.isDebug() && !StringUtils.equalsAny(request.getRunMode(), ApiRunMode.DEFINITION.name())) {
|
||||
|
@ -148,6 +148,18 @@ public class JMeterService {
|
|||
runner.run(request.getReportId());
|
||||
}
|
||||
|
||||
private void fileProcessing(JmeterRunRequestDTO request) {
|
||||
ElementUtil.coverArguments(request.getHashTree());
|
||||
//解析HashTree里的文件信息
|
||||
List<AttachmentBodyFile> attachmentBodyFileList = ApiFileUtil.getExecuteFile(request.getHashTree(), request.getReportId(), false);
|
||||
if (CollectionUtils.isNotEmpty(attachmentBodyFileList)) {
|
||||
redisTemplateService.setIfAbsent(JmxFileUtil.getExecuteFileKeyInRedis(request.getReportId()),
|
||||
JmxFileUtil.getRedisJmxFileString(attachmentBodyFileList));
|
||||
}
|
||||
redisTemplateService.setIfAbsent(JmxFileUtil.getExecuteScriptKey(request.getReportId(), request.getTestId()),
|
||||
new MsTestPlan().getJmx(request.getHashTree()));
|
||||
}
|
||||
|
||||
private void runNode(JmeterRunRequestDTO request) {
|
||||
request.setKafkaConfig(KafkaConfig.getKafka());
|
||||
//获取MinIO配置和系统下的插件jar包
|
||||
|
@ -160,14 +172,7 @@ public class JMeterService {
|
|||
try {
|
||||
// 缓存调试脚本
|
||||
if (request.getHashTree() != null) {
|
||||
ElementUtil.coverArguments(request.getHashTree());
|
||||
//解析HashTree里的文件信息
|
||||
List<AttachmentBodyFile> attachmentBodyFileList = ApiFileUtil.getExecuteFile(request.getHashTree(), request.getReportId(), false);
|
||||
if (CollectionUtils.isNotEmpty(attachmentBodyFileList)) {
|
||||
redisTemplateService.setIfAbsent(JmxFileUtil.getExecuteFileKeyInRedis(request.getReportId()), JmxFileUtil.getRedisJmxFileString(attachmentBodyFileList));
|
||||
}
|
||||
|
||||
redisTemplateService.setIfAbsent(JmxFileUtil.getExecuteScriptKey(request.getReportId(), request.getTestId()), new MsTestPlan().getJmx(request.getHashTree()));
|
||||
this.fileProcessing(request);
|
||||
}
|
||||
LoggerUtil.info("开始发送请求[ " + request.getTestId() + " ] 到K8S节点执行", request.getReportId());
|
||||
final Engine engine = EngineFactory.createApiEngine(request);
|
||||
|
@ -191,16 +196,7 @@ public class JMeterService {
|
|||
List<TestResource> resources = GenerateHashTreeUtil.setPoolResource(request.getPoolId());
|
||||
if (request.getHashTree() != null) {
|
||||
// 过程变量处理
|
||||
ElementUtil.coverArguments(request.getHashTree());
|
||||
|
||||
|
||||
//解析HashTree里的文件信息
|
||||
List<AttachmentBodyFile> attachmentBodyFileList = ApiFileUtil.getExecuteFile(request.getHashTree(), request.getReportId(), false);
|
||||
if (CollectionUtils.isNotEmpty(attachmentBodyFileList)) {
|
||||
redisTemplateService.setIfAbsent(JmxFileUtil.getExecuteFileKeyInRedis(request.getReportId()), JmxFileUtil.getRedisJmxFileString(attachmentBodyFileList));
|
||||
}
|
||||
|
||||
redisTemplateService.setIfAbsent(JmxFileUtil.getExecuteScriptKey(request.getReportId(), request.getTestId()), new MsTestPlan().getJmx(request.getHashTree()));
|
||||
this.fileProcessing(request);
|
||||
request.setHashTree(null);
|
||||
}
|
||||
apiPoolDebugService.run(request, resources);
|
||||
|
|
|
@ -6,9 +6,11 @@ import io.metersphere.base.domain.ApiScenarioWithBLOBs;
|
|||
import io.metersphere.base.mapper.ApiScenarioReferenceIdMapper;
|
||||
import io.metersphere.base.mapper.ext.ExtApiScenarioReferenceIdMapper;
|
||||
import io.metersphere.commons.constants.ElementConstants;
|
||||
import io.metersphere.commons.constants.PropertyConstant;
|
||||
import io.metersphere.commons.utils.JSONUtil;
|
||||
import io.metersphere.commons.utils.SessionUtils;
|
||||
import io.metersphere.service.MsHashTreeService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.ibatis.session.ExecutorType;
|
||||
|
@ -20,7 +22,6 @@ import org.mybatis.spring.SqlSessionUtils;
|
|||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
@ -40,28 +41,12 @@ public class ApiScenarioReferenceIdService {
|
|||
@Resource
|
||||
private SqlSessionFactory sqlSessionFactory;
|
||||
|
||||
public List<ApiScenarioReferenceId> findByReferenceIds(List<String> deleteIds) {
|
||||
if (CollectionUtils.isEmpty(deleteIds)) {
|
||||
return new ArrayList<>(0);
|
||||
} else {
|
||||
ApiScenarioReferenceIdExample example = new ApiScenarioReferenceIdExample();
|
||||
example.createCriteria().andReferenceIdIn(deleteIds);
|
||||
return apiScenarioReferenceIdMapper.selectByExample(example);
|
||||
}
|
||||
}
|
||||
|
||||
public void deleteByScenarioId(String scenarioId) {
|
||||
ApiScenarioReferenceIdExample example = new ApiScenarioReferenceIdExample();
|
||||
example.createCriteria().andApiScenarioIdEqualTo(scenarioId);
|
||||
apiScenarioReferenceIdMapper.deleteByExample(example);
|
||||
}
|
||||
|
||||
public void deleteByScenarioIds(List<String> scenarioIds) {
|
||||
ApiScenarioReferenceIdExample example = new ApiScenarioReferenceIdExample();
|
||||
example.createCriteria().andApiScenarioIdIn(scenarioIds);
|
||||
apiScenarioReferenceIdMapper.deleteByExample(example);
|
||||
}
|
||||
|
||||
public void saveApiAndScenarioRelation(ApiScenarioWithBLOBs scenario) {
|
||||
if (scenario.getId() == null) {
|
||||
return;
|
||||
|
@ -71,25 +56,6 @@ public class ApiScenarioReferenceIdService {
|
|||
this.insertApiScenarioReferenceIds(savedList);
|
||||
}
|
||||
|
||||
public void saveApiAndScenarioRelation(List<ApiScenarioWithBLOBs> scenarios) {
|
||||
if (CollectionUtils.isNotEmpty(scenarios)) {
|
||||
List<String> idList = new ArrayList<>(scenarios.size());
|
||||
LinkedList<ApiScenarioReferenceId> savedList = new LinkedList<>();
|
||||
scenarios.forEach(scenario -> {
|
||||
if (StringUtils.isNotEmpty(scenario.getId())) {
|
||||
idList.add(scenario.getId());
|
||||
savedList.addAll(this.getApiAndScenarioRelation(scenario));
|
||||
}
|
||||
});
|
||||
if (CollectionUtils.isNotEmpty(idList)) {
|
||||
ApiScenarioReferenceIdExample example = new ApiScenarioReferenceIdExample();
|
||||
example.createCriteria().andApiScenarioIdIn(idList);
|
||||
apiScenarioReferenceIdMapper.deleteByExample(example);
|
||||
}
|
||||
this.insertApiScenarioReferenceIds(savedList);
|
||||
}
|
||||
}
|
||||
|
||||
public void insertApiScenarioReferenceIds(List<ApiScenarioReferenceId> list) {
|
||||
if (CollectionUtils.isNotEmpty(list)) {
|
||||
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
|
||||
|
@ -114,13 +80,13 @@ public class ApiScenarioReferenceIdService {
|
|||
JSONArray hashTree = jsonObject.optJSONArray(MsHashTreeService.HASH_TREE);
|
||||
for (int index = 0; index < hashTree.length(); index++) {
|
||||
JSONObject item = hashTree.optJSONObject(index);
|
||||
if (item == null) {
|
||||
if (item == null || StringUtils.equals(item.optString(PropertyConstant.TYPE), ElementConstants.SCENARIO)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (item.has(MsHashTreeService.ID) && item.has(MsHashTreeService.REFERENCED)) {
|
||||
String url = null;
|
||||
String method = null;
|
||||
String method;
|
||||
if (item.has(MsHashTreeService.PATH) && StringUtils.isNotEmpty(MsHashTreeService.PATH)) {
|
||||
url = item.optString(MsHashTreeService.PATH);
|
||||
} else if (item.has(MsHashTreeService.URL)) {
|
||||
|
@ -157,7 +123,8 @@ public class ApiScenarioReferenceIdService {
|
|||
|
||||
private String getMethodFromSample(JSONObject item) {
|
||||
String method = null;
|
||||
if (item.has(MsHashTreeService.TYPE) && item.has(MsHashTreeService.METHOD) && StringUtils.equalsIgnoreCase(item.optString(MsHashTreeService.TYPE), ElementConstants.HTTP_SAMPLER))
|
||||
if (item.has(MsHashTreeService.TYPE) && item.has(MsHashTreeService.METHOD)
|
||||
&& StringUtils.equalsIgnoreCase(item.optString(MsHashTreeService.TYPE), ElementConstants.HTTP_SAMPLER))
|
||||
method = item.optString(MsHashTreeService.METHOD);
|
||||
return method;
|
||||
}
|
||||
|
@ -198,16 +165,6 @@ public class ApiScenarioReferenceIdService {
|
|||
return deepRelations;
|
||||
}
|
||||
|
||||
public List<ApiScenarioReferenceId> findByReferenceIdsAndRefType(List<String> deleteIds, String referenceType) {
|
||||
if (CollectionUtils.isEmpty(deleteIds)) {
|
||||
return new ArrayList<>(0);
|
||||
} else {
|
||||
ApiScenarioReferenceIdExample example = new ApiScenarioReferenceIdExample();
|
||||
example.createCriteria().andReferenceIdIn(deleteIds).andReferenceTypeEqualTo(referenceType);
|
||||
return apiScenarioReferenceIdMapper.selectByExample(example);
|
||||
}
|
||||
}
|
||||
|
||||
public List<ApiScenarioReferenceId> selectUrlByProjectId(String projectId, String versionId) {
|
||||
return extApiScenarioReferenceIdMapper.selectUrlByProjectId(projectId, versionId);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue