fix(测试跟踪): 修复测试计划运行接口用例时时执行结果没有写入测试计划与接口用例关联表的问题
--bug=1020245 --user=宋天阳 【测试计划】计划中关联1400+的接口用例和20条场景用例,执行该测试计划成功后-报告统计中未更新 https://www.tapd.cn/55049933/s/1304670
This commit is contained in:
parent
3a977e134b
commit
6956335481
|
@ -68,7 +68,6 @@ public class MsApiBackendListener extends AbstractBackendListenerClient implemen
|
||||||
sampleResults = RetryResultUtil.clearLoops(sampleResults);
|
sampleResults = RetryResultUtil.clearLoops(sampleResults);
|
||||||
JMeterBase.resultFormatting(sampleResults, dto);
|
JMeterBase.resultFormatting(sampleResults, dto);
|
||||||
testResultService.saveResults(dto);
|
testResultService.saveResults(dto);
|
||||||
|
|
||||||
resultVO = ReportStatusUtil.getStatus(dto, resultVO);
|
resultVO = ReportStatusUtil.getStatus(dto, resultVO);
|
||||||
dto.getArbitraryData().put(CommonConstants.LOCAL_STATUS_KEY, resultVO);
|
dto.getArbitraryData().put(CommonConstants.LOCAL_STATUS_KEY, resultVO);
|
||||||
sampleResults.clear();
|
sampleResults.clear();
|
||||||
|
|
|
@ -14,6 +14,7 @@ import io.metersphere.commons.enums.ApiReportStatus;
|
||||||
import io.metersphere.commons.enums.ExecutionExecuteTypeEnum;
|
import io.metersphere.commons.enums.ExecutionExecuteTypeEnum;
|
||||||
import io.metersphere.commons.utils.CommonBeanFactory;
|
import io.metersphere.commons.utils.CommonBeanFactory;
|
||||||
import io.metersphere.commons.utils.DateUtils;
|
import io.metersphere.commons.utils.DateUtils;
|
||||||
|
import io.metersphere.commons.utils.HttpHeaderUtils;
|
||||||
import io.metersphere.constants.RunModeConstants;
|
import io.metersphere.constants.RunModeConstants;
|
||||||
import io.metersphere.dto.BaseSystemConfigDTO;
|
import io.metersphere.dto.BaseSystemConfigDTO;
|
||||||
import io.metersphere.dto.ResultDTO;
|
import io.metersphere.dto.ResultDTO;
|
||||||
|
@ -26,6 +27,7 @@ import io.metersphere.service.scenario.ApiScenarioReportStructureService;
|
||||||
import io.metersphere.service.scenario.ApiScenarioService;
|
import io.metersphere.service.scenario.ApiScenarioService;
|
||||||
import org.apache.commons.beanutils.BeanMap;
|
import org.apache.commons.beanutils.BeanMap;
|
||||||
import org.apache.commons.collections4.CollectionUtils;
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
|
import org.apache.commons.collections4.MapUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
@ -86,6 +88,17 @@ public class TestResultService {
|
||||||
* @param dto 执行结果
|
* @param dto 执行结果
|
||||||
*/
|
*/
|
||||||
public void saveResults(ResultDTO 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<String> environmentList = new LinkedList<>();
|
List<String> environmentList = new LinkedList<>();
|
||||||
if (dto.getArbitraryData() != null && dto.getArbitraryData().containsKey("ENV")) {
|
if (dto.getArbitraryData() != null && dto.getArbitraryData().containsKey("ENV")) {
|
||||||
|
@ -106,6 +119,10 @@ public class TestResultService {
|
||||||
// 场景报告结果处理
|
// 场景报告结果处理
|
||||||
apiScenarioReportService.saveResult(dto);
|
apiScenarioReportService.saveResult(dto);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (StringUtils.isNotEmpty(userId)) {
|
||||||
|
HttpHeaderUtils.clearUser();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -31,6 +31,7 @@ import org.apache.ibatis.session.SqlSessionFactory;
|
||||||
import org.mybatis.spring.SqlSessionUtils;
|
import org.mybatis.spring.SqlSessionUtils;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
@ -133,6 +134,17 @@ public class ApiDefinitionExecResultService {
|
||||||
ApiTestCaseMapper batchApiTestCaseMapper = sqlSession.getMapper(ApiTestCaseMapper.class);
|
ApiTestCaseMapper batchApiTestCaseMapper = sqlSession.getMapper(ApiTestCaseMapper.class);
|
||||||
|
|
||||||
for (ResultDTO dto : resultDTOS) {
|
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);
|
this.mergeRetryResults(dto);
|
||||||
if (CollectionUtils.isNotEmpty(dto.getRequestResults())) {
|
if (CollectionUtils.isNotEmpty(dto.getRequestResults())) {
|
||||||
for (RequestResult item : dto.getRequestResults()) {
|
for (RequestResult item : dto.getRequestResults()) {
|
||||||
|
@ -156,6 +168,10 @@ public class ApiDefinitionExecResultService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (StringUtils.isNotEmpty(userId)) {
|
||||||
|
HttpHeaderUtils.clearUser();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
sqlSession.flushStatements();
|
sqlSession.flushStatements();
|
||||||
if (sqlSession != null && sqlSessionFactory != null) {
|
if (sqlSession != null && sqlSessionFactory != null) {
|
||||||
|
|
Loading…
Reference in New Issue