From d0021e6b088e0a2b8a016dd36df2acb207d88c6c Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Thu, 24 Nov 2022 18:47:23 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=B5=8B=E8=AF=95=E8=AE=A1=E5=88=92=E6=89=A7?= =?UTF-8?q?=E8=A1=8C=E6=8A=A5=E5=91=8A=E7=BB=93=E6=9E=9C=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1020245 --user=赵勇 【测试计划】计划中关联1400+的接口用例和20条场景用例,执行该测试计划成功后-报告统计中未更新 https://www.tapd.cn/55049933/s/1304778 --- .../service/MsHashTreeService.java | 3 --- .../service/TestResultService.java | 24 ++----------------- .../ApiDefinitionExecResultService.java | 19 ++------------- 3 files changed, 4 insertions(+), 42 deletions(-) diff --git a/api-test/backend/src/main/java/io/metersphere/service/MsHashTreeService.java b/api-test/backend/src/main/java/io/metersphere/service/MsHashTreeService.java index c1c56d090f..cf2eb6b29e 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/MsHashTreeService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/MsHashTreeService.java @@ -7,7 +7,6 @@ import io.metersphere.api.dto.definition.request.ElementUtil; import io.metersphere.base.domain.ApiScenarioWithBLOBs; import io.metersphere.base.domain.ApiTestCaseWithBLOBs; import io.metersphere.base.domain.Project; -import io.metersphere.base.mapper.ApiDefinitionMapper; import io.metersphere.base.mapper.ApiScenarioMapper; import io.metersphere.base.mapper.ProjectMapper; import io.metersphere.base.mapper.ext.ExtApiScenarioMapper; @@ -39,8 +38,6 @@ public class MsHashTreeService { @Resource private ApiDefinitionService apiDefinitionService; @Resource - private ApiDefinitionMapper apiDefinitionMapper; - @Resource private ExtApiScenarioMapper extApiScenarioMapper; @Resource private BaseProjectApplicationService baseProjectApplicationService; diff --git a/api-test/backend/src/main/java/io/metersphere/service/TestResultService.java b/api-test/backend/src/main/java/io/metersphere/service/TestResultService.java index e99828591f..3d4ef3aa7f 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/TestResultService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/TestResultService.java @@ -14,7 +14,6 @@ import io.metersphere.commons.enums.ApiReportStatus; import io.metersphere.commons.enums.ExecutionExecuteTypeEnum; import io.metersphere.commons.utils.CommonBeanFactory; import io.metersphere.commons.utils.DateUtils; -import io.metersphere.commons.utils.HttpHeaderUtils; import io.metersphere.constants.RunModeConstants; import io.metersphere.dto.BaseSystemConfigDTO; import io.metersphere.dto.ResultDTO; @@ -27,7 +26,6 @@ import io.metersphere.service.scenario.ApiScenarioReportStructureService; import io.metersphere.service.scenario.ApiScenarioService; import org.apache.commons.beanutils.BeanMap; import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.collections4.MapUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -88,17 +86,6 @@ public class TestResultService { * @param dto 执行结果 */ public void saveResults(ResultDTO dto) { - String userId = null; - if (MapUtils.isNotEmpty(dto.getExtendedParameters()) && dto.getExtendedParameters().containsKey("userId")) { - userId = dto.getExtendedParameters().get("userId").toString(); - } - if (StringUtils.isNotEmpty(userId)) { - User user = new User(); - user.setId(userId); - user.setName(userId); - HttpHeaderUtils.runAsUser(user); - } - // 处理环境 List environmentList = new LinkedList<>(); if (dto.getArbitraryData() != null && dto.getArbitraryData().containsKey("ENV")) { @@ -119,10 +106,6 @@ public class TestResultService { // 场景报告结果处理 apiScenarioReportService.saveResult(dto); } - - if (StringUtils.isNotEmpty(userId)) { - HttpHeaderUtils.clearUser(); - } } /** @@ -151,14 +134,11 @@ public class TestResultService { } } //测试计划定时任务-接口执行逻辑的话,需要同步测试计划的报告数据 - if (StringUtils.equals(key, "schedule-task")) { - apiDefinitionExecResultService.batchSaveApiResult(resultDTOS, true); - } else if (StringUtils.equals(key, "api-test-case-task")) { - apiDefinitionExecResultService.batchSaveApiResult(resultDTOS, false); + if (StringUtils.equalsAny(key, "schedule-task", "api-test-case-task")) { + apiDefinitionExecResultService.batchSaveApiResult(resultDTOS); } else if (StringUtils.equalsAny(key, "api-scenario-task")) { apiScenarioReportService.batchSaveResult(resultDTOS); } - } } diff --git a/api-test/backend/src/main/java/io/metersphere/service/definition/ApiDefinitionExecResultService.java b/api-test/backend/src/main/java/io/metersphere/service/definition/ApiDefinitionExecResultService.java index 3c51d9384c..edbf26289e 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/definition/ApiDefinitionExecResultService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/definition/ApiDefinitionExecResultService.java @@ -123,7 +123,7 @@ public class ApiDefinitionExecResultService { } } - public void batchSaveApiResult(List resultDTOS, boolean isSchedule) { + public void batchSaveApiResult(List resultDTOS) { if (CollectionUtils.isEmpty(resultDTOS)) { return; } @@ -134,17 +134,6 @@ public class ApiDefinitionExecResultService { ApiTestCaseMapper batchApiTestCaseMapper = sqlSession.getMapper(ApiTestCaseMapper.class); for (ResultDTO dto : resultDTOS) { - String userId = null; - if (MapUtils.isNotEmpty(dto.getExtendedParameters()) && dto.getExtendedParameters().containsKey("userId")) { - userId = dto.getExtendedParameters().get("userId").toString(); - } - if (StringUtils.isNotEmpty(userId)) { - User user = new User(); - user.setId(userId); - user.setName(userId); - HttpHeaderUtils.runAsUser(user); - } - this.mergeRetryResults(dto); if (CollectionUtils.isNotEmpty(dto.getRequestResults())) { for (RequestResult item : dto.getRequestResults()) { @@ -168,10 +157,6 @@ public class ApiDefinitionExecResultService { } } } - - if (StringUtils.isNotEmpty(userId)) { - HttpHeaderUtils.clearUser(); - } } sqlSession.flushStatements(); if (sqlSession != null && sqlSessionFactory != null) { @@ -403,8 +388,8 @@ public class ApiDefinitionExecResultService { if (StringUtils.isNotEmpty(saveResult.getTriggerMode()) && saveResult.getTriggerMode().equals("CASE")) { saveResult.setTriggerMode(TriggerMode.MANUAL.name()); } + editStatus(saveResult, type, status, saveResult.getCreateTime(), saveResult.getId(), testId); if (batchMapper == null) { - editStatus(saveResult, type, status, saveResult.getCreateTime(), saveResult.getId(), testId); apiDefinitionExecResultMapper.updateByPrimaryKeySelective(saveResult); } else { batchMapper.updateByPrimaryKeySelective(saveResult);