fix(接口测试): 场景中禁用的步骤批量执行时也生成了报告步骤

This commit is contained in:
AgAngle 2024-04-03 17:12:15 +08:00 committed by Craftsman
parent 5fb59a66f7
commit ecac585d31
2 changed files with 29 additions and 4 deletions

View File

@ -138,7 +138,7 @@ public class ApiScenarioBatchRunService {
String reportId = null;
try {
ApiScenarioDetail apiScenarioDetail = apiScenarioService.get(id);
ApiScenarioDetail apiScenarioDetail = apiScenarioService.getForRun(id);
if (apiScenarioDetail == null) {
if (runModeConfig.isIntegratedReport()) {
// 用例不存在则在执行集合中删除
@ -281,7 +281,7 @@ public class ApiScenarioBatchRunService {
* @param queueDetail
*/
public void executeNextTask(ExecutionQueue queue, ExecutionQueueDetail queueDetail) {
ApiScenarioDetail apiScenarioDetail = apiScenarioService.get(queueDetail.getResourceId());
ApiScenarioDetail apiScenarioDetail = apiScenarioService.getForRun(queueDetail.getResourceId());
if (apiScenarioDetail == null) {
LogUtils.info("当前执行任务的用例已删除 {}", queueDetail.getResourceId());
return;
@ -405,7 +405,7 @@ public class ApiScenarioBatchRunService {
}
Long requestCount = 0L;
while (queueDetail != null) {
ApiScenarioDetail apiScenarioDetail = apiScenarioService.get(queueDetail.getResourceId());
ApiScenarioDetail apiScenarioDetail = apiScenarioService.getForRun(queueDetail.getResourceId());
if (apiScenarioDetail == null) {
LogUtils.info("当前场景已删除 {}", queueDetail.getResourceId());
continue;

View File

@ -1275,7 +1275,7 @@ public class ApiScenarioService extends MoveNodeService {
}
public TaskRequestDTO run(String id, String reportId, String userId) {
ApiScenarioDetail apiScenarioDetail = get(id);
ApiScenarioDetail apiScenarioDetail = getForRun(id);
// 解析生成待执行的场景树
MsScenario msScenario = new MsScenario();
@ -1942,9 +1942,34 @@ public class ApiScenarioService extends MoveNodeService {
return apiScenarios.getFirst();
}
public ApiScenarioDetail getForRun(String scenarioId) {
ApiScenarioDetail apiScenarioDetail = get(scenarioId);
filerDisableSteps(apiScenarioDetail.getSteps());
return apiScenarioDetail;
}
/**
* 过滤掉禁用的步骤
*/
public List<? extends ApiScenarioStepCommonDTO> filerDisableSteps(List<? extends ApiScenarioStepCommonDTO> steps) {
if (CollectionUtils.isEmpty(steps)) {
return List.of();
}
return steps.stream()
.filter(step -> {
boolean isEnable = BooleanUtils.isTrue(step.getEnable());
if (isEnable) {
step.setChildren(filerDisableSteps(step.getChildren()));
}
return isEnable;
})
.toList();
}
public ApiScenarioDetail get(String scenarioId) {
ApiScenario apiScenario = checkResourceIsNoDeleted(scenarioId);
ApiScenarioDetail apiScenarioDetail = BeanUtils.copyBean(new ApiScenarioDetail(), apiScenario);
apiScenarioDetail.setSteps(List.of());
ApiScenarioBlob apiScenarioBlob = apiScenarioBlobMapper.selectByPrimaryKey(scenarioId);
if (apiScenarioBlob != null) {
apiScenarioDetail.setScenarioConfig(JSON.parseObject(new String(apiScenarioBlob.getConfig()), ScenarioConfig.class));