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

This commit is contained in:
fit2-zhao 2021-12-01 15:32:06 +08:00 committed by fit2-zhao
parent 9eadbc68c1
commit f1a08fcdc2
1 changed files with 17 additions and 10 deletions

View File

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