fix(接口定义): 修复接口定义带/导致转存性能测试失败的缺陷 (#17485)

--bug=1016355 --user=王孝刚 【接口测试】github#17452,接口自动化名字带 /
,转成性能测试保存会报错:文件上传失败 https://www.tapd.cn/55049933/s/1234397

Co-authored-by: wxg0103 <727495428@qq.com>
This commit is contained in:
MeterSphere Bot 2022-08-29 13:54:39 +08:00 committed by GitHub
parent 58359cb409
commit 4c25c046a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 45 additions and 41 deletions

View File

@ -301,53 +301,54 @@ public class EngineFactory {
try { try {
Element hashTree = null; Element hashTree = null;
Document rootDocument = null; Document rootDocument = null;
for (FileMetadata fileMetadata : jmxFiles) { if (CollectionUtils.isNotEmpty(jmxFiles)) {
// 兼容处理 for (FileMetadata fileMetadata : jmxFiles) {
byte[] bytes = fileMetadataService.loadFileAsBytes(fileMetadata.getId()); // 兼容处理
InputStream inputSource = new ByteArrayInputStream(bytes); byte[] bytes = fileMetadataService.loadFileAsBytes(fileMetadata.getId());
if (hashTree == null) { InputStream inputSource = new ByteArrayInputStream(bytes);
rootDocument = EngineSourceParserFactory.getDocument(inputSource); if (hashTree == null) {
Element jmeterTestPlan = rootDocument.getRootElement(); rootDocument = EngineSourceParserFactory.getDocument(inputSource);
List<Element> childNodes = jmeterTestPlan.elements(); Element jmeterTestPlan = rootDocument.getRootElement();
List<Element> childNodes = jmeterTestPlan.elements();
outer: outer:
for (Element node : childNodes) { for (Element node : childNodes) {
// jmeterTestPlan的子元素肯定是<hashTree></hashTree> // jmeterTestPlan的子元素肯定是<hashTree></hashTree>
List<Element> childNodes1 = node.elements(); List<Element> childNodes1 = node.elements();
for (Element item : childNodes1) { for (Element item : childNodes1) {
if (StringUtils.equalsIgnoreCase("TestPlan", item.getName())) { if (StringUtils.equalsIgnoreCase("TestPlan", item.getName())) {
hashTree = getNextSibling(item); hashTree = getNextSibling(item);
break outer; break outer;
}
} }
} }
} else {
Document document = EngineSourceParserFactory.getDocument(inputSource);
Element jmeterTestPlan = document.getRootElement();
List<Element> childNodes = jmeterTestPlan.elements();
for (Element node : childNodes) {
// jmeterTestPlan的子元素肯定是<hashTree></hashTree>
Element secondHashTree = node;
List<Element> secondChildNodes = secondHashTree.elements();
for (Element item : secondChildNodes) {
if (StringUtils.equalsIgnoreCase("TestPlan", item.getName())) {
secondHashTree = getNextSibling(item);
break;
}
}
if (StringUtils.equalsIgnoreCase("hashTree", secondHashTree.getName())) {
List<Element> itemChildNodes = secondHashTree.elements();
for (Element item1 : itemChildNodes) {
hashTree.add((Element) item1.clone());
}
}
}
} }
} else { inputSource.close();
Document document = EngineSourceParserFactory.getDocument(inputSource);
Element jmeterTestPlan = document.getRootElement();
List<Element> childNodes = jmeterTestPlan.elements();
for (Element node : childNodes) {
// jmeterTestPlan的子元素肯定是<hashTree></hashTree>
Element secondHashTree = node;
List<Element> secondChildNodes = secondHashTree.elements();
for (Element item : secondChildNodes) {
if (StringUtils.equalsIgnoreCase("TestPlan", item.getName())) {
secondHashTree = getNextSibling(item);
break;
}
}
if (StringUtils.equalsIgnoreCase("hashTree", secondHashTree.getName())) {
List<Element> itemChildNodes = secondHashTree.elements();
for (Element item1 : itemChildNodes) {
hashTree.add((Element) item1.clone());
}
}
}
} }
// return EngineSourceParserFactory.getBytes(rootDocument);
inputSource.close();
} }
return EngineSourceParserFactory.getBytes(rootDocument);
} catch (Exception e) { } catch (Exception e) {
MSException.throwException(e); MSException.throwException(e);
} }

View File

@ -143,6 +143,9 @@ export default {
let data = returnData.scenarioJmxList; let data = returnData.scenarioJmxList;
data.forEach(d => { data.forEach(d => {
let jmxName = d.name + "_" + new Date().getTime() + ".jmx"; let jmxName = d.name + "_" + new Date().getTime() + ".jmx";
if (jmxName.indexOf("/") !== -1) {
jmxName = jmxName.replace(/\//g, "");
}
let threadGroups = findThreadGroup(d.jmx, jmxName); let threadGroups = findThreadGroup(d.jmx, jmxName);
threadGroups.forEach(tg => { threadGroups.forEach(tg => {
tg.options = {}; tg.options = {};