fix(接口测试): 修复嵌套循环报告步骤顺序错误问题
--bug=1012523 --user=赵勇 【通用功能】测试报告,接口报告和UI报告,循环里套循环的时候,报告显示顺序不是循环的顺序 https://www.tapd.cn/55049933/s/1177398
This commit is contained in:
parent
f459900d17
commit
f120e85230
|
@ -8,12 +8,12 @@ import io.metersphere.api.dto.ApiScenarioReportBaseInfoDTO;
|
|||
import io.metersphere.api.dto.ApiScenarioReportDTO;
|
||||
import io.metersphere.api.dto.RequestResultExpandDTO;
|
||||
import io.metersphere.api.dto.StepTreeDTO;
|
||||
import io.metersphere.api.dto.definition.request.ElementUtil;
|
||||
import io.metersphere.api.exec.utils.ResultParseUtil;
|
||||
import io.metersphere.api.service.vo.ApiDefinitionExecResultVo;
|
||||
import io.metersphere.base.domain.*;
|
||||
import io.metersphere.base.mapper.*;
|
||||
import io.metersphere.base.mapper.ext.ExtApiScenarioReportResultMapper;
|
||||
import io.metersphere.commons.constants.CommandType;
|
||||
import io.metersphere.commons.constants.ExecuteResult;
|
||||
import io.metersphere.commons.constants.MsTestElementConstants;
|
||||
import io.metersphere.commons.constants.ReportTypeConstants;
|
||||
|
@ -23,7 +23,6 @@ import io.metersphere.commons.utils.LogUtil;
|
|||
import io.metersphere.constants.RunModeConstants;
|
||||
import io.metersphere.dto.RequestResult;
|
||||
import io.metersphere.utils.LoggerUtil;
|
||||
import io.metersphere.commons.constants.CommandType;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
@ -264,7 +263,8 @@ public class ApiScenarioReportStructureService {
|
|||
}
|
||||
}
|
||||
|
||||
public void reportFormatting(List<StepTreeDTO> dtoList, Map<String, List<ApiScenarioReportResultWithBLOBs>> maps) {
|
||||
public void reportFormatting(List<StepTreeDTO> dtoList, Map<String, List<ApiScenarioReportResultWithBLOBs>> maps, boolean isLoops) {
|
||||
// 按照创建时间排序
|
||||
for (int index = 0; index < dtoList.size(); index++) {
|
||||
StepTreeDTO dto = dtoList.get(index);
|
||||
dto.setIndex((index + 1));
|
||||
|
@ -342,7 +342,7 @@ public class ApiScenarioReportStructureService {
|
|||
}
|
||||
|
||||
if (CollectionUtils.isNotEmpty(dto.getChildren())) {
|
||||
reportFormatting(dto.getChildren(), maps);
|
||||
reportFormatting(dto.getChildren(), maps, StringUtils.equalsIgnoreCase(dto.getType(), "LoopController"));
|
||||
|
||||
if (StringUtils.isEmpty(dto.getErrorCode())) {
|
||||
//统计child的errorCode,合并到parent中
|
||||
|
@ -401,25 +401,51 @@ public class ApiScenarioReportStructureService {
|
|||
dto.setTotalStatus("fail");
|
||||
}
|
||||
}
|
||||
// 循环步骤请求从新排序
|
||||
if (isLoops) {
|
||||
this.orderLoops(dtoList);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 循环步骤请求从新排序
|
||||
*/
|
||||
private void orderLoops(List<StepTreeDTO> dtoList) {
|
||||
try {
|
||||
if (dtoList.stream().filter(e -> e.getValue() != null && ElementUtil.requests.contains(e.getType())).collect(Collectors.toList()).size() == dtoList.size()) {
|
||||
List<StepTreeDTO> unList = dtoList.stream().filter(e -> e.getValue() != null
|
||||
&& ((StringUtils.equalsIgnoreCase(e.getType(), "DubboSampler") && e.getValue().getStartTime() == 0) || StringUtils.equalsIgnoreCase(e.getTotalStatus(), ExecuteResult.unexecute.name())))
|
||||
.collect(Collectors.toList());
|
||||
List<StepTreeDTO> list = dtoList.stream().filter(e -> e.getValue().getStartTime() != 0).collect(Collectors.toList());
|
||||
list = list.stream().sorted(Comparator.comparing(x -> x.getValue().getStartTime())).collect(Collectors.toList());
|
||||
unList = unList.stream().sorted(Comparator.comparing(x -> x.getIndex())).collect(Collectors.toList());
|
||||
for (StepTreeDTO unListDTO : unList) {
|
||||
int index = unListDTO.getIndex();
|
||||
List<StepTreeDTO> steps = dtoList.stream().filter(e -> e.getValue() == null)
|
||||
.collect(Collectors.toList());
|
||||
// 都是没有结果的步骤,不需要再次排序
|
||||
if (dtoList.size() == steps.size()) {
|
||||
return;
|
||||
}
|
||||
// 非正常执行结束的请求结果
|
||||
List<StepTreeDTO> unList = dtoList.stream().filter(e -> e.getValue() != null
|
||||
&& ((StringUtils.equalsIgnoreCase(e.getType(), "DubboSampler") && e.getValue().getStartTime() == 0)
|
||||
|| StringUtils.equalsIgnoreCase(e.getTotalStatus(), ExecuteResult.unexecute.name())))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 有效数据按照时间排序
|
||||
List<StepTreeDTO> list = dtoList.stream().filter(e -> e.getValue() != null && e.getValue().getStartTime() != 0).collect(Collectors.toList());
|
||||
list = list.stream().sorted(Comparator.comparing(x -> x.getValue().getStartTime())).collect(Collectors.toList());
|
||||
unList = unList.stream().sorted(Comparator.comparing(x -> x.getIndex())).collect(Collectors.toList());
|
||||
// 处理请求结果开始时间为0的数据
|
||||
for (StepTreeDTO unListDTO : unList) {
|
||||
int index = unListDTO.getIndex();
|
||||
if (index > 0) {
|
||||
list.add(index - 1, unListDTO);
|
||||
}
|
||||
for (int index = 0; index < list.size(); index++) {
|
||||
list.get(index).setIndex((index + 1));
|
||||
}
|
||||
dtoList.clear();
|
||||
dtoList.addAll(list);
|
||||
}
|
||||
for (int index = 0; index < list.size(); index++) {
|
||||
list.get(index).setIndex((index + 1));
|
||||
}
|
||||
// 处理步骤为空的数据
|
||||
for (StepTreeDTO step : steps) {
|
||||
int index = step.getIndex();
|
||||
if (index > 0) {
|
||||
list.add(index - 1, step);
|
||||
}
|
||||
}
|
||||
dtoList.clear();
|
||||
dtoList.addAll(list);
|
||||
} catch (Exception e) {
|
||||
LogUtil.error(e);
|
||||
}
|
||||
|
@ -587,7 +613,7 @@ public class ApiScenarioReportStructureService {
|
|||
|
||||
// 匹配结果
|
||||
Map<String, List<ApiScenarioReportResultWithBLOBs>> maps = reportResults.stream().collect(Collectors.groupingBy(ApiScenarioReportResult::getResourceId));
|
||||
this.reportFormatting(stepList, maps);
|
||||
this.reportFormatting(stepList, maps, false);
|
||||
|
||||
reportDTO = this.countReportNum(stepList, reportDTO);
|
||||
// 统计场景数据
|
||||
|
@ -695,24 +721,6 @@ public class ApiScenarioReportStructureService {
|
|||
return reportDTO;
|
||||
}
|
||||
|
||||
private void stepChildrenErrorCalculate(List<StepTreeDTO> dtoList, AtomicLong isError, AtomicLong isErrorReport, AtomicLong isUnExecute) {
|
||||
for (StepTreeDTO step : dtoList) {
|
||||
if (step.getValue() != null) {
|
||||
if (step.getValue() instanceof RequestResultExpandDTO
|
||||
&& StringUtils.equalsIgnoreCase(((RequestResultExpandDTO) step.getValue()).getStatus(), ExecuteResult.unexecute.name())) {
|
||||
isUnExecute.set(isUnExecute.longValue() + 1);
|
||||
} else if (step.getValue().getError() > 0 || !step.getValue().isSuccess()) {
|
||||
isError.set(isError.longValue() + 1);
|
||||
}
|
||||
if (StringUtils.isNotEmpty(step.getErrorCode())) {
|
||||
isErrorReport.set(isErrorReport.longValue() + 1);
|
||||
}
|
||||
} else if (CollectionUtils.isNotEmpty(step.getChildren())) {
|
||||
stepChildrenErrorCalculate(step.getChildren(), isError, isErrorReport, isUnExecute);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public RequestResult selectReportContent(String stepId) {
|
||||
RequestResult result = new RequestResult();
|
||||
try {
|
||||
|
|
Loading…
Reference in New Issue