fix(接口测试): 修复串行顺序错误问题
--bug=1009552 --user=赵勇 【接口测试】测试用例批量执行,串行,执行顺序不对 https://www.tapd.cn/55049933/s/1091257
This commit is contained in:
parent
abda752b58
commit
959099fe1f
|
@ -22,7 +22,9 @@ import io.metersphere.dto.MsExecResponseDTO;
|
|||
import io.metersphere.dto.RunModeConfigDTO;
|
||||
import io.metersphere.service.EnvironmentGroupProjectService;
|
||||
import io.metersphere.utils.LoggerUtil;
|
||||
import org.apache.commons.beanutils.BeanComparator;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.collections4.comparators.FixedOrderComparator;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.ibatis.session.ExecutorType;
|
||||
import org.apache.ibatis.session.SqlSession;
|
||||
|
@ -32,10 +34,7 @@ import org.springframework.stereotype.Service;
|
|||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
@Service
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
|
@ -145,6 +144,16 @@ public class ApiCaseExecuteService {
|
|||
List<ApiTestCaseWithBLOBs> list = apiTestCaseMapper.selectByExampleWithBLOBs(example);
|
||||
LoggerUtil.debug("查询到执行数据:" + list.size());
|
||||
|
||||
if (request.getConfig() != null && request.getConfig().getMode().equals(RunModeConstants.SERIAL.toString())) {
|
||||
if (request.getCondition() == null || !request.getCondition().isSelectAll()) {
|
||||
// 按照id指定顺序排序
|
||||
FixedOrderComparator<String> fixedOrderComparator = new FixedOrderComparator<String>(request.getIds());
|
||||
fixedOrderComparator.setUnknownObjectBehavior(FixedOrderComparator.UnknownObjectBehavior.BEFORE);
|
||||
BeanComparator beanComparator = new BeanComparator("id", fixedOrderComparator);
|
||||
Collections.sort(list, beanComparator);
|
||||
}
|
||||
}
|
||||
|
||||
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
|
||||
ApiDefinitionExecResultMapper batchMapper = sqlSession.getMapper(ApiDefinitionExecResultMapper.class);
|
||||
if (StringUtils.isEmpty(request.getTriggerMode())) {
|
||||
|
@ -152,7 +161,7 @@ public class ApiCaseExecuteService {
|
|||
}
|
||||
|
||||
List<MsExecResponseDTO> responseDTOS = new LinkedList<>();
|
||||
Map<String, ApiDefinitionExecResult> executeQueue = new HashMap<>();
|
||||
Map<String, ApiDefinitionExecResult> executeQueue = new LinkedHashMap<>();
|
||||
String status = request.getConfig().getMode().equals(RunModeConstants.SERIAL.toString()) ? APITestStatus.Waiting.name() : APITestStatus.Running.name();
|
||||
list.forEach(caseWithBLOBs -> {
|
||||
ApiDefinitionExecResult report = ApiDefinitionExecResultUtil.initBase(caseWithBLOBs.getId(), APITestStatus.Running.name(), null, request.getConfig());
|
||||
|
|
|
@ -220,7 +220,6 @@
|
|||
@stopScenario="stop"
|
||||
@setDomain="setDomain"
|
||||
@openScenario="openScenario"
|
||||
@reloadResult="reloadResult"
|
||||
@editScenarioAdvance="editScenarioAdvance"/>
|
||||
</span>
|
||||
</el-tree>
|
||||
|
@ -515,7 +514,6 @@ export default {
|
|||
dialogVisible:false,
|
||||
newScenarioDefinition:[],
|
||||
currentItem: {},
|
||||
debugResults: [],
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
|
@ -692,7 +690,6 @@ export default {
|
|||
this.reqTotalTime = 0;
|
||||
this.reqTotal = 0;
|
||||
this.reqSuccess = 0;
|
||||
this.debugResults = [];
|
||||
},
|
||||
clearResult(arr) {
|
||||
if (arr) {
|
||||
|
@ -808,23 +805,6 @@ export default {
|
|||
}
|
||||
})
|
||||
},
|
||||
setParentIndex(stepArray, fullPath) {
|
||||
for (let i in stepArray) {
|
||||
// 添加debug结果
|
||||
stepArray[i].data.parentIndex = fullPath ? fullPath + "_" + stepArray[i].data.index : stepArray[i].data.index;
|
||||
if (stepArray[i].childNodes && stepArray[i].childNodes.length > 0) {
|
||||
this.setParentIndex(stepArray[i].childNodes, stepArray[i].data.parentIndex);
|
||||
}
|
||||
}
|
||||
},
|
||||
reloadResult() {
|
||||
if (this.debugResults && this.debugResults.length > 0) {
|
||||
this.setParentIndex(this.$refs.stepTree.root.childNodes);
|
||||
this.debugResults.forEach(item => {
|
||||
this.runningEvaluation(item);
|
||||
})
|
||||
}
|
||||
},
|
||||
runningEvaluation(resultData) {
|
||||
if (this.$refs.stepTree && this.$refs.stepTree.root) {
|
||||
this.$refs.stepTree.root.childNodes.forEach(item => {
|
||||
|
@ -869,9 +849,6 @@ export default {
|
|||
}
|
||||
}
|
||||
this.runningEvaluation(e.data);
|
||||
if (e.data && e.data.startsWith("result_")) {
|
||||
this.debugResults.push(e.data);
|
||||
}
|
||||
this.message = getUUID();
|
||||
if (e.data && e.data.indexOf("MS_TEST_END") !== -1) {
|
||||
this.runScenario = undefined;
|
||||
|
|
|
@ -124,6 +124,9 @@ export default {
|
|||
this.scenario.projectId = getCurrentProjectID();
|
||||
}
|
||||
if (this.scenario.id && this.scenario.referenced === 'REF' && !this.scenario.loaded) {
|
||||
let scenarios = JSON.parse(JSON.stringify(this.scenario.hashTree));
|
||||
let map = new Map();
|
||||
this.formatResult(map, scenarios);
|
||||
this.result = this.$get("/api/automation/getApiScenario/" + this.scenario.id, response => {
|
||||
if (response.data) {
|
||||
this.scenario.loaded = true;
|
||||
|
@ -150,7 +153,7 @@ export default {
|
|||
this.scenario.headers = obj.headers;
|
||||
this.scenario.variables = obj.variables;
|
||||
this.scenario.environmentMap = obj.environmentMap;
|
||||
this.$emit('reloadResult');
|
||||
this.setResult(this.scenario.hashTree, map);
|
||||
this.$emit('refReload');
|
||||
}
|
||||
})
|
||||
|
@ -193,6 +196,34 @@ export default {
|
|||
},
|
||||
},
|
||||
methods: {
|
||||
formatResult(map, scenarios) {
|
||||
scenarios.forEach(item => {
|
||||
if (this.stepFilter.get("AllSamplerProxy").indexOf(item.type) !== -1 && item.requestResult) {
|
||||
let key = (item.id ? item.id : item.resourceId) + "_" + item.index;
|
||||
if (map.has(key)) {
|
||||
map.get(key).push(...item.requestResult);
|
||||
} else {
|
||||
map.set(key, item.requestResult);
|
||||
}
|
||||
}
|
||||
if (item.hashTree && item.hashTree.length > 0) {
|
||||
this.formatResult(map, item.hashTree);
|
||||
}
|
||||
})
|
||||
},
|
||||
setResult(array, scenarios) {
|
||||
if (array && scenarios) {
|
||||
array.forEach(item => {
|
||||
let key = (item.id ? item.id : item.resourceId) + "_" + item.index;
|
||||
if (scenarios.has(key)) {
|
||||
item.requestResult = scenarios.get(key);
|
||||
}
|
||||
if (item.hashTree && item.hashTree.length > 0) {
|
||||
this.setResult(item.hashTree, scenarios);
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
run() {
|
||||
this.scenario.run = true;
|
||||
let runScenario = JSON.parse(JSON.stringify(this.scenario));
|
||||
|
|
|
@ -40,7 +40,6 @@
|
|||
@setDomain="setDomain"
|
||||
@savePreParams="savePreParams"
|
||||
@editScenarioAdvance="editScenarioAdvance"
|
||||
@reloadResult="reloadResult"
|
||||
/>
|
||||
</keep-alive>
|
||||
</div>
|
||||
|
@ -256,9 +255,6 @@ export default {
|
|||
editScenarioAdvance(data) {
|
||||
this.$emit('editScenarioAdvance', data);
|
||||
},
|
||||
reloadResult() {
|
||||
this.$emit('reloadResult');
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
|
|
@ -116,9 +116,6 @@
|
|||
this.reload();
|
||||
},
|
||||
},
|
||||
created() {
|
||||
this.$emit('reloadResult');
|
||||
},
|
||||
methods: {
|
||||
reload() {
|
||||
this.loading = true
|
||||
|
|
|
@ -169,9 +169,6 @@ export default {
|
|||
},
|
||||
};
|
||||
},
|
||||
created() {
|
||||
this.$emit('reloadResult');
|
||||
},
|
||||
watch: {
|
||||
message() {
|
||||
this.reload();
|
||||
|
|
Loading…
Reference in New Issue