fix(接口测试): 修复循环控制器下步骤最终执行状态未更新问题
--bug=1022325 --user=赵勇 【接口测试】接口场景-次循环下自定义脚本切换语言后执行成功-显示状态失败 https://www.tapd.cn/55049933/s/1330932
This commit is contained in:
parent
e152243496
commit
9d6ad8ae42
|
@ -68,6 +68,7 @@ import java.net.URL;
|
|||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class ElementUtil {
|
||||
private static final String PRE = "PRE";
|
||||
|
@ -402,61 +403,31 @@ public class ElementUtil {
|
|||
|
||||
public static void mergeHashTree(MsTestElement element, LinkedList<MsTestElement> targetHashTree) {
|
||||
try {
|
||||
LinkedList<MsTestElement> sourceHashTree = element.getHashTree();
|
||||
if (CollectionUtils.isNotEmpty(sourceHashTree) && CollectionUtils.isNotEmpty(targetHashTree) && sourceHashTree.size() < targetHashTree.size()) {
|
||||
if (CollectionUtils.isNotEmpty(element.getHashTree())
|
||||
&& CollectionUtils.isNotEmpty(targetHashTree)
|
||||
&& element.getHashTree().size() == targetHashTree.size()) {
|
||||
element.setHashTree(targetHashTree);
|
||||
return;
|
||||
}
|
||||
List<String> sourceIds = new ArrayList<>();
|
||||
List<String> delIds = new ArrayList<>();
|
||||
Map<String, MsTestElement> updateMap = new HashMap<>();
|
||||
if (CollectionUtils.isEmpty(sourceHashTree)) {
|
||||
if (CollectionUtils.isNotEmpty(targetHashTree)) {
|
||||
element.setHashTree(targetHashTree);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(targetHashTree)) {
|
||||
for (MsTestElement item : targetHashTree) {
|
||||
if (StringUtils.isNotEmpty(item.getId())) {
|
||||
updateMap.put(item.getId(), item);
|
||||
}
|
||||
}
|
||||
}
|
||||
// 找出待更新内容和源已经被删除的内容
|
||||
if (CollectionUtils.isNotEmpty(sourceHashTree)) {
|
||||
for (int i = 0; i < sourceHashTree.size(); i++) {
|
||||
MsTestElement source = sourceHashTree.get(i);
|
||||
if (source != null) {
|
||||
sourceIds.add(source.getId());
|
||||
if (!StringUtils.equals(source.getLabel(), "SCENARIO-REF-STEP") && StringUtils.isNotEmpty(source.getId())) {
|
||||
if (updateMap.containsKey(source.getId())) {
|
||||
sourceHashTree.set(i, updateMap.get(source.getId()));
|
||||
} else {
|
||||
delIds.add(source.getId());
|
||||
}
|
||||
}
|
||||
// 历史数据兼容
|
||||
if (StringUtils.isEmpty(source.getId()) && !StringUtils.equals(source.getLabel(), "SCENARIO-REF-STEP") && i < targetHashTree.size()) {
|
||||
sourceHashTree.set(i, targetHashTree.get(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// 合并步骤
|
||||
List<MsTestElement> sourceList = Stream.of(element.getHashTree(), targetHashTree)
|
||||
.flatMap(Collection::stream)
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 删除多余的步骤
|
||||
sourceHashTree.removeIf(item -> item != null && delIds.contains(item.getId()));
|
||||
// 补充新增的源引用步骤
|
||||
if (CollectionUtils.isNotEmpty(targetHashTree)) {
|
||||
for (MsTestElement item : targetHashTree) {
|
||||
if (!sourceIds.contains(item.getId())) {
|
||||
sourceHashTree.add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(sourceHashTree)) {
|
||||
element.setHashTree(sourceHashTree);
|
||||
// 历史数据补充id
|
||||
sourceList.forEach(item -> {
|
||||
if (StringUtils.isBlank(item.getId())) {
|
||||
item.setId(UUID.randomUUID().toString());
|
||||
}
|
||||
});
|
||||
|
||||
sourceList = sourceList.stream().collect(Collectors
|
||||
.collectingAndThen(
|
||||
Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(MsTestElement::getId))),
|
||||
ArrayList::new));
|
||||
|
||||
element.setHashTree((LinkedList<MsTestElement>) sourceList);
|
||||
} catch (Exception e) {
|
||||
element.setHashTree(targetHashTree);
|
||||
}
|
||||
|
|
|
@ -407,87 +407,6 @@ export default {
|
|||
copyRow() {
|
||||
this.$emit('copyRow', this.request, this.node);
|
||||
},
|
||||
setUrl(url) {
|
||||
try {
|
||||
new URL(url);
|
||||
this.request.url = url;
|
||||
} catch (e) {
|
||||
if (url && (!url.startsWith('http://') || !url.startsWith('https://'))) {
|
||||
if (!this.isCustomizeReq) {
|
||||
this.request.path = url;
|
||||
this.request.url = undefined;
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
mergeHashTree(targetHashTree) {
|
||||
let sourceHashTree = this.request.hashTree;
|
||||
// 历史数据兼容
|
||||
if (sourceHashTree && targetHashTree && sourceHashTree.length < targetHashTree.length) {
|
||||
this.request.hashTree = targetHashTree;
|
||||
return;
|
||||
}
|
||||
let sourceIds = [];
|
||||
let delIds = [];
|
||||
let updateMap = new Map();
|
||||
if (!sourceHashTree || sourceHashTree.length == 0) {
|
||||
if (targetHashTree) {
|
||||
targetHashTree.forEach((item) => {
|
||||
item.disabled = true;
|
||||
});
|
||||
this.request.hashTree = targetHashTree;
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (targetHashTree) {
|
||||
for (let i in targetHashTree) {
|
||||
targetHashTree[i].disabled = true;
|
||||
if (targetHashTree[i].id) {
|
||||
updateMap.set(targetHashTree[i].id, targetHashTree[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (sourceHashTree && sourceHashTree.length > 0) {
|
||||
for (let index in sourceHashTree) {
|
||||
let source = sourceHashTree[index];
|
||||
sourceIds.push(source.id);
|
||||
// 历史数据兼容
|
||||
if (source.label !== 'SCENARIO-REF-STEP' && source.id) {
|
||||
if (updateMap.has(source.id)) {
|
||||
Object.assign(sourceHashTree[index], updateMap.get(source.id));
|
||||
sourceHashTree[index].disabled = true;
|
||||
sourceHashTree[index].label = '';
|
||||
sourceHashTree[index].enable = updateMap.get(source.id).enable;
|
||||
} else {
|
||||
delIds.push(source.id);
|
||||
}
|
||||
}
|
||||
// 历史数据兼容
|
||||
if (!source.id && source.label !== 'SCENARIO-REF-STEP' && index < targetHashTree.length) {
|
||||
Object.assign(sourceHashTree[index], targetHashTree[index]);
|
||||
sourceHashTree[index].disabled = true;
|
||||
sourceHashTree[index].label = '';
|
||||
sourceHashTree[index].enable = targetHashTree[index].enable;
|
||||
}
|
||||
}
|
||||
}
|
||||
// 删除多余的步骤
|
||||
delIds.forEach((item) => {
|
||||
const removeIndex = sourceHashTree.findIndex((d) => d.id && d.id === item);
|
||||
sourceHashTree.splice(removeIndex, 1);
|
||||
});
|
||||
|
||||
// 补充新增的源引用步骤
|
||||
if (targetHashTree) {
|
||||
targetHashTree.forEach((item) => {
|
||||
if (sourceIds.indexOf(item.id) === -1) {
|
||||
item.disabled = true;
|
||||
this.request.hashTree.push(item);
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
sort() {
|
||||
for (let i in this.request.hashTree) {
|
||||
this.request.hashTree[i].index = Number(i) + 1;
|
||||
|
|
|
@ -250,6 +250,9 @@ export default {
|
|||
}
|
||||
},
|
||||
forStatus() {
|
||||
if (!this.jsr223Processor.requestResult || this.jsr223Processor.requestResult.length == 0) {
|
||||
this.reqSuccess = true;
|
||||
}
|
||||
if (this.jsr223Processor && this.jsr223Processor.result && this.jsr223Processor.result.length > 0) {
|
||||
this.jsr223Processor.result.forEach((item) => {
|
||||
item.requestResult.forEach((req) => {
|
||||
|
|
Loading…
Reference in New Issue