From 69563354817107f80ce2d679cbb4bf402685c215 Mon Sep 17 00:00:00 2001 From: song-tianyang Date: Thu, 24 Nov 2022 17:11:52 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=B5=8B=E8=AF=95=E8=B7=9F=E8=B8=AA):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=B5=8B=E8=AF=95=E8=AE=A1=E5=88=92=E8=BF=90?= =?UTF-8?q?=E8=A1=8C=E6=8E=A5=E5=8F=A3=E7=94=A8=E4=BE=8B=E6=97=B6=E6=97=B6?= =?UTF-8?q?=E6=89=A7=E8=A1=8C=E7=BB=93=E6=9E=9C=E6=B2=A1=E6=9C=89=E5=86=99?= =?UTF-8?q?=E5=85=A5=E6=B5=8B=E8=AF=95=E8=AE=A1=E5=88=92=E4=B8=8E=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E7=94=A8=E4=BE=8B=E5=85=B3=E8=81=94=E8=A1=A8=E7=9A=84?= =?UTF-8?q?=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/1304670 --- .../api/jmeter/MsApiBackendListener.java | 1 - .../metersphere/service/TestResultService.java | 17 +++++++++++++++++ .../ApiDefinitionExecResultService.java | 16 ++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/api-test/backend/src/main/java/io/metersphere/api/jmeter/MsApiBackendListener.java b/api-test/backend/src/main/java/io/metersphere/api/jmeter/MsApiBackendListener.java index 6d2470e0d4..033e0160ad 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/jmeter/MsApiBackendListener.java +++ b/api-test/backend/src/main/java/io/metersphere/api/jmeter/MsApiBackendListener.java @@ -68,7 +68,6 @@ public class MsApiBackendListener extends AbstractBackendListenerClient implemen sampleResults = RetryResultUtil.clearLoops(sampleResults); JMeterBase.resultFormatting(sampleResults, dto); testResultService.saveResults(dto); - resultVO = ReportStatusUtil.getStatus(dto, resultVO); dto.getArbitraryData().put(CommonConstants.LOCAL_STATUS_KEY, resultVO); sampleResults.clear(); 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 c1f67e62a1..e99828591f 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,6 +14,7 @@ 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; @@ -26,6 +27,7 @@ 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; @@ -86,6 +88,17 @@ 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")) { @@ -106,6 +119,10 @@ public class TestResultService { // 场景报告结果处理 apiScenarioReportService.saveResult(dto); } + + if (StringUtils.isNotEmpty(userId)) { + HttpHeaderUtils.clearUser(); + } } /** 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 7347c2e387..3c51d9384c 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 @@ -31,6 +31,7 @@ import org.apache.ibatis.session.SqlSessionFactory; import org.mybatis.spring.SqlSessionUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; + import javax.annotation.Resource; import java.util.*; import java.util.stream.Collectors; @@ -133,6 +134,17 @@ 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()) { @@ -156,6 +168,10 @@ public class ApiDefinitionExecResultService { } } } + + if (StringUtils.isNotEmpty(userId)) { + HttpHeaderUtils.clearUser(); + } } sqlSession.flushStatements(); if (sqlSession != null && sqlSessionFactory != null) {