fix(接口定义): 修复批量执行接口用例结果未拿到问题

This commit is contained in:
fit2-zhao 2021-07-22 10:49:03 +08:00 committed by fit2-zhao
parent 188b152e81
commit 4118f8c702
1 changed files with 15 additions and 9 deletions

View File

@ -61,15 +61,21 @@ public class ApiDefinitionExecResultService {
if (CollectionUtils.isNotEmpty(result.getScenarios())) { if (CollectionUtils.isNotEmpty(result.getScenarios())) {
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH); SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
ApiDefinitionExecResultMapper definitionExecResultMapper = sqlSession.getMapper(ApiDefinitionExecResultMapper.class); ApiDefinitionExecResultMapper definitionExecResultMapper = sqlSession.getMapper(ApiDefinitionExecResultMapper.class);
final boolean[] isFirst = {true};
result.getScenarios().forEach(scenarioResult -> { result.getScenarios().forEach(scenarioResult -> {
if (scenarioResult != null && CollectionUtils.isNotEmpty(scenarioResult.getRequestResults())) { if (scenarioResult != null && CollectionUtils.isNotEmpty(scenarioResult.getRequestResults())) {
scenarioResult.getRequestResults().forEach(item -> { scenarioResult.getRequestResults().forEach(item -> {
ApiDefinitionExecResult saveResult = definitionExecResultMapper.selectByPrimaryKey(result.getTestId()); ApiDefinitionExecResult saveResult = definitionExecResultMapper.selectByPrimaryKey(result.getTestId());
item.getResponseResult().setConsole(result.getConsole()); item.getResponseResult().setConsole(result.getConsole());
boolean saved = true; boolean saved = true;
if (saveResult == null) { if (saveResult == null || scenarioResult.getRequestResults().size() > 1) {
saveResult = new ApiDefinitionExecResult(); saveResult = new ApiDefinitionExecResult();
if (isFirst[0]) {
isFirst[0] = false;
saveResult.setId(result.getTestId()); saveResult.setId(result.getTestId());
} else {
saveResult.setId(UUID.randomUUID().toString());
}
saveResult.setActuator("LOCAL"); saveResult.setActuator("LOCAL");
saveResult.setName(item.getName()); saveResult.setName(item.getName());
saveResult.setTriggerMode(triggerMode); saveResult.setTriggerMode(triggerMode);