From 2e97fcaa25cc80821ceed8bdb80c6b36b6f198af Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Fri, 25 Nov 2022 17:01:29 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E6=B5=8B=E8=AF=95=E8=B7=9F=E8=B8=AA):?= =?UTF-8?q?=20=E4=BC=98=E5=8C=96=E5=A4=A7=E9=87=8F=E7=94=A8=E4=BE=8B?= =?UTF-8?q?=E6=89=A7=E8=A1=8C=E5=AD=98=E5=82=A8=E6=95=88=E7=8E=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1020298 --user=赵勇 【测试跟踪】github#20206,性能问题测试跟踪-测试计划-选择一计划手动执行性能很慢 https://www.tapd.cn/55049933/s/1305598 --- .../ApiDefinitionExecResultService.java | 37 ++++++++++++++----- .../service/plan/TestPlanApiCaseService.java | 6 +++ .../plan/TestPlanScenarioCaseService.java | 6 +++ 3 files changed, 39 insertions(+), 10 deletions(-) diff --git a/api-test/backend/src/main/java/io/metersphere/service/definition/ApiDefinitionExecResultService.java b/api-test/backend/src/main/java/io/metersphere/service/definition/ApiDefinitionExecResultService.java index edbf26289e..09d8730850 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/definition/ApiDefinitionExecResultService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/definition/ApiDefinitionExecResultService.java @@ -132,6 +132,7 @@ public class ApiDefinitionExecResultService { SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH); ApiDefinitionExecResultMapper definitionExecResultMapper = sqlSession.getMapper(ApiDefinitionExecResultMapper.class); ApiTestCaseMapper batchApiTestCaseMapper = sqlSession.getMapper(ApiTestCaseMapper.class); + TestPlanApiCaseMapper planApiCaseMapper = sqlSession.getMapper(TestPlanApiCaseMapper.class); for (ResultDTO dto : resultDTOS) { this.mergeRetryResults(dto); @@ -143,7 +144,7 @@ public class ApiDefinitionExecResultService { result.setResourceId(dto.getTestId()); 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")) { User user = null; @@ -264,14 +265,30 @@ public class ApiDefinitionExecResultService { saveResult.setName(name); } - public void batchEditStatus(String type, String status, String reportId, String testId, ApiTestCaseMapper batchApiTestCaseMapper) { - // 更新用例最后执行结果 - ApiTestCaseWithBLOBs caseWithBLOBs = new ApiTestCaseWithBLOBs(); - caseWithBLOBs.setId(testId); - caseWithBLOBs.setLastResultId(reportId); - caseWithBLOBs.setStatus(status); - caseWithBLOBs.setUpdateTime(System.currentTimeMillis()); - batchApiTestCaseMapper.updateByPrimaryKeySelective(caseWithBLOBs); + public void batchEditStatus(String type, String status, String reportId, String testId, + TestPlanApiCaseMapper batchTestPlanApiCaseMapper, + ApiTestCaseMapper batchApiTestCaseMapper) { + if (StringUtils.equalsAnyIgnoreCase(type, ApiRunMode.API_PLAN.name(), ApiRunMode.SCHEDULE_API_PLAN.name(), + ApiRunMode.JENKINS_API_PLAN.name(), ApiRunMode.MANUAL_PLAN.name())) { + TestPlanApiCase apiCase = new TestPlanApiCase(); + apiCase.setId(testId); + 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")) { saveResult.setTriggerMode(TriggerMode.MANUAL.name()); } - editStatus(saveResult, type, status, saveResult.getCreateTime(), saveResult.getId(), testId); if (batchMapper == null) { + editStatus(saveResult, type, status, saveResult.getCreateTime(), saveResult.getId(), testId); apiDefinitionExecResultMapper.updateByPrimaryKeySelective(saveResult); } else { batchMapper.updateByPrimaryKeySelective(saveResult); diff --git a/api-test/backend/src/main/java/io/metersphere/service/plan/TestPlanApiCaseService.java b/api-test/backend/src/main/java/io/metersphere/service/plan/TestPlanApiCaseService.java index eac885ecfc..25ab21c772 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/plan/TestPlanApiCaseService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/plan/TestPlanApiCaseService.java @@ -579,6 +579,9 @@ public class TestPlanApiCaseService { testPlanService.statusReset(request.getPlanId()); sqlSession.flushStatements(); + if (sqlSession != null && sqlSessionFactory != null) { + SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory); + } } public void relevanceByTestIds(List ids, String planId) { @@ -634,6 +637,9 @@ public class TestPlanApiCaseService { } } sqlSession.flushStatements(); + if (sqlSession != null && sqlSessionFactory != null) { + SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory); + } } } diff --git a/api-test/backend/src/main/java/io/metersphere/service/plan/TestPlanScenarioCaseService.java b/api-test/backend/src/main/java/io/metersphere/service/plan/TestPlanScenarioCaseService.java index 8b22d4c6c8..7e9fcdd251 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/plan/TestPlanScenarioCaseService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/plan/TestPlanScenarioCaseService.java @@ -370,6 +370,9 @@ public class TestPlanScenarioCaseService { mapper.updateByPrimaryKeyWithBLOBs(testPlanApiScenario); } sqlSession.flushStatements(); + if (sqlSession != null && sqlSessionFactory != null) { + SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory); + } } } @@ -727,6 +730,9 @@ public class TestPlanScenarioCaseService { } } sqlSession.flushStatements(); + if (sqlSession != null && sqlSessionFactory != null) { + SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory); + } } }