refactor(测试跟踪): 优化大量用例执行存储效率

--bug=1020298 --user=赵勇 【测试跟踪】github#20206,性能问题测试跟踪-测试计划-选择一计划手动执行性能很慢 https://www.tapd.cn/55049933/s/1305598
This commit is contained in:
fit2-zhao 2022-11-25 17:01:29 +08:00 committed by fit2-zhao
parent eee8920b11
commit 2e97fcaa25
3 changed files with 39 additions and 10 deletions

View File

@ -132,6 +132,7 @@ public class ApiDefinitionExecResultService {
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH); SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
ApiDefinitionExecResultMapper definitionExecResultMapper = sqlSession.getMapper(ApiDefinitionExecResultMapper.class); ApiDefinitionExecResultMapper definitionExecResultMapper = sqlSession.getMapper(ApiDefinitionExecResultMapper.class);
ApiTestCaseMapper batchApiTestCaseMapper = sqlSession.getMapper(ApiTestCaseMapper.class); ApiTestCaseMapper batchApiTestCaseMapper = sqlSession.getMapper(ApiTestCaseMapper.class);
TestPlanApiCaseMapper planApiCaseMapper = sqlSession.getMapper(TestPlanApiCaseMapper.class);
for (ResultDTO dto : resultDTOS) { for (ResultDTO dto : resultDTOS) {
this.mergeRetryResults(dto); this.mergeRetryResults(dto);
@ -143,7 +144,7 @@ public class ApiDefinitionExecResultService {
result.setResourceId(dto.getTestId()); result.setResourceId(dto.getTestId());
apiExecutionInfoService.insertExecutionInfo(result); apiExecutionInfoService.insertExecutionInfo(result);
// 批量更新关联关系状态 // 批量更新关联关系状态
batchEditStatus(dto.getRunMode(), result.getStatus(), result.getId(), dto.getTestId(), batchApiTestCaseMapper); batchEditStatus(dto.getRunMode(), result.getStatus(), result.getId(), dto.getTestId(), planApiCaseMapper, batchApiTestCaseMapper);
} }
if (result != null && !StringUtils.startsWithAny(dto.getRunMode(), "SCHEDULE")) { if (result != null && !StringUtils.startsWithAny(dto.getRunMode(), "SCHEDULE")) {
User user = null; User user = null;
@ -264,14 +265,30 @@ public class ApiDefinitionExecResultService {
saveResult.setName(name); saveResult.setName(name);
} }
public void batchEditStatus(String type, String status, String reportId, String testId, ApiTestCaseMapper batchApiTestCaseMapper) { public void batchEditStatus(String type, String status, String reportId, String testId,
// 更新用例最后执行结果 TestPlanApiCaseMapper batchTestPlanApiCaseMapper,
ApiTestCaseWithBLOBs caseWithBLOBs = new ApiTestCaseWithBLOBs(); ApiTestCaseMapper batchApiTestCaseMapper) {
caseWithBLOBs.setId(testId); if (StringUtils.equalsAnyIgnoreCase(type, ApiRunMode.API_PLAN.name(), ApiRunMode.SCHEDULE_API_PLAN.name(),
caseWithBLOBs.setLastResultId(reportId); ApiRunMode.JENKINS_API_PLAN.name(), ApiRunMode.MANUAL_PLAN.name())) {
caseWithBLOBs.setStatus(status); TestPlanApiCase apiCase = new TestPlanApiCase();
caseWithBLOBs.setUpdateTime(System.currentTimeMillis()); apiCase.setId(testId);
batchApiTestCaseMapper.updateByPrimaryKeySelective(caseWithBLOBs); apiCase.setStatus(status);
apiCase.setUpdateTime(System.currentTimeMillis());
batchTestPlanApiCaseMapper.updateByPrimaryKeySelective(apiCase);
TestCaseReviewApiCase reviewApiCase = new TestCaseReviewApiCase();
reviewApiCase.setId(testId);
reviewApiCase.setStatus(status);
reviewApiCase.setUpdateTime(System.currentTimeMillis());
} else {
// 更新用例最后执行结果
ApiTestCaseWithBLOBs caseWithBLOBs = new ApiTestCaseWithBLOBs();
caseWithBLOBs.setId(testId);
caseWithBLOBs.setLastResultId(reportId);
caseWithBLOBs.setStatus(status);
caseWithBLOBs.setUpdateTime(System.currentTimeMillis());
batchApiTestCaseMapper.updateByPrimaryKeySelective(caseWithBLOBs);
}
} }
/** /**
@ -388,8 +405,8 @@ public class ApiDefinitionExecResultService {
if (StringUtils.isNotEmpty(saveResult.getTriggerMode()) && saveResult.getTriggerMode().equals("CASE")) { if (StringUtils.isNotEmpty(saveResult.getTriggerMode()) && saveResult.getTriggerMode().equals("CASE")) {
saveResult.setTriggerMode(TriggerMode.MANUAL.name()); saveResult.setTriggerMode(TriggerMode.MANUAL.name());
} }
editStatus(saveResult, type, status, saveResult.getCreateTime(), saveResult.getId(), testId);
if (batchMapper == null) { if (batchMapper == null) {
editStatus(saveResult, type, status, saveResult.getCreateTime(), saveResult.getId(), testId);
apiDefinitionExecResultMapper.updateByPrimaryKeySelective(saveResult); apiDefinitionExecResultMapper.updateByPrimaryKeySelective(saveResult);
} else { } else {
batchMapper.updateByPrimaryKeySelective(saveResult); batchMapper.updateByPrimaryKeySelective(saveResult);

View File

@ -579,6 +579,9 @@ public class TestPlanApiCaseService {
testPlanService.statusReset(request.getPlanId()); testPlanService.statusReset(request.getPlanId());
sqlSession.flushStatements(); sqlSession.flushStatements();
if (sqlSession != null && sqlSessionFactory != null) {
SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory);
}
} }
public void relevanceByTestIds(List<String> ids, String planId) { public void relevanceByTestIds(List<String> ids, String planId) {
@ -634,6 +637,9 @@ public class TestPlanApiCaseService {
} }
} }
sqlSession.flushStatements(); sqlSession.flushStatements();
if (sqlSession != null && sqlSessionFactory != null) {
SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory);
}
} }
} }

View File

@ -370,6 +370,9 @@ public class TestPlanScenarioCaseService {
mapper.updateByPrimaryKeyWithBLOBs(testPlanApiScenario); mapper.updateByPrimaryKeyWithBLOBs(testPlanApiScenario);
} }
sqlSession.flushStatements(); sqlSession.flushStatements();
if (sqlSession != null && sqlSessionFactory != null) {
SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory);
}
} }
} }
@ -727,6 +730,9 @@ public class TestPlanScenarioCaseService {
} }
} }
sqlSession.flushStatements(); sqlSession.flushStatements();
if (sqlSession != null && sqlSessionFactory != null) {
SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory);
}
} }
} }