fix(接口测试): 并发报告存储处理,执行前优先提交入库

This commit is contained in:
fit2-zhao 2021-12-01 15:32:06 +08:00 committed by BugKing
parent 614433e399
commit 34b90d2484
1 changed files with 17 additions and 10 deletions

View File

@ -1440,16 +1440,23 @@ public class ApiAutomationService {
* @param request * @param request
*/ */
private void parallel(Map<String, RunModeDataDTO> executeQueue, RunScenarioRequest request) { private void parallel(Map<String, RunModeDataDTO> executeQueue, RunScenarioRequest request) {
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH); Thread thread = new Thread(new Runnable() {
ApiScenarioReportMapper batchMapper = sqlSession.getMapper(ApiScenarioReportMapper.class); @Override
// 开始并发执行 public void run() {
for (String reportId : executeQueue.keySet()) { SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
//存储报告 ApiScenarioReportMapper batchMapper = sqlSession.getMapper(ApiScenarioReportMapper.class);
APIScenarioReportResult report = executeQueue.get(reportId).getReport(); // 开始并发执行
batchMapper.insert(report); for (String reportId : executeQueue.keySet()) {
MessageCache.scenarioExecResourceLock.put(reportId, report); //存储报告
} APIScenarioReportResult report = executeQueue.get(reportId).getReport();
sqlSession.flushStatements(); batchMapper.insert(report);
MessageCache.scenarioExecResourceLock.put(reportId, report);
}
sqlSession.commit();
sqlSession.clearCache();
}
});
thread.start();
for (String reportId : executeQueue.keySet()) { for (String reportId : executeQueue.keySet()) {
// 增加一个本地锁防止并发找不到资源 // 增加一个本地锁防止并发找不到资源