perf(测试跟踪): 优化测试计划关联功能用例性能

https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001018291
--user=郭雨琦
This commit is contained in:
guoyuqi 2022-10-21 17:29:13 +08:00 committed by f2c-ci-robot[bot]
parent 2161159627
commit e3531d5ee2
1 changed files with 39 additions and 34 deletions

View File

@ -10,7 +10,6 @@ import io.metersphere.base.mapper.ext.ExtTestPlanReportMapper;
import io.metersphere.base.mapper.ext.ExtTestPlanTestCaseMapper; import io.metersphere.base.mapper.ext.ExtTestPlanTestCaseMapper;
import io.metersphere.commons.constants.*; import io.metersphere.commons.constants.*;
import io.metersphere.commons.exception.MSException; import io.metersphere.commons.exception.MSException;
import io.metersphere.commons.user.SessionUser;
import io.metersphere.commons.utils.*; import io.metersphere.commons.utils.*;
import io.metersphere.constants.RunModeConstants; import io.metersphere.constants.RunModeConstants;
import io.metersphere.dto.*; import io.metersphere.dto.*;
@ -574,41 +573,47 @@ public class TestPlanService {
} }
public void caseTestRelevance(PlanCaseRelevanceRequest request, List<String> testCaseIds) { public void caseTestRelevance(PlanCaseRelevanceRequest request, List<String> testCaseIds) {
//同步添加关联的接口和测试用例 //同步添加关联的接口和测试用例
if (request.getChecked()) { if (!request.getChecked()) {
if (!testCaseIds.isEmpty()) { return;
testCaseIds.forEach(caseId -> { }
List<TestCaseTest> list = new ArrayList<>(); if (CollectionUtils.isEmpty(testCaseIds)) {
TestCaseTestExample examp = new TestCaseTestExample(); return;
examp.createCriteria().andTestCaseIdEqualTo(caseId); }
if (testCaseTestMapper.countByExample(examp) > 0) { List<TestCaseTest> list;
list = testCaseTestMapper.selectByExample(examp); TestCaseTestExample exam = new TestCaseTestExample();
} exam.createCriteria().andTestCaseIdIn(testCaseIds);
list = testCaseTestMapper.selectByExample(exam);
if (CollectionUtils.isEmpty(list)) {
return;
}
List<String> apiCaseIds = new ArrayList<>();
List<String> scenarioIds = new ArrayList<>();
List<String> performanceIds = new ArrayList<>();
buildCaseIdList(list, apiCaseIds, scenarioIds, performanceIds);
startRelevance(request, apiCaseIds, scenarioIds, performanceIds);
}
List<String> apiCaseIds = new ArrayList<>(); private void startRelevance(PlanCaseRelevanceRequest request, List<String> apiCaseIds, List<String> scenarioIds, List<String> performanceIds) {
List<String> scenarioIds = new ArrayList<>(); try {
List<String> performanceIds = new ArrayList<>(); relevanceTestCaseTest(apiCaseIds, request.getPlanId(), planTestPlanApiCaseService::relevanceByTestIds);
relevanceTestCaseTest(scenarioIds, request.getPlanId(), planTestPlanScenarioCaseService::relevanceByTestIds);
relevanceTestCaseTest(performanceIds, request.getPlanId(), planTestPlanLoadCaseService::relevanceByTestIds);
} catch (MSException e) {
LogUtil.error(e);
}
}
for (TestCaseTest l : list) { private static void buildCaseIdList(List<TestCaseTest> list, List<String> apiCaseIds, List<String> scenarioIds, List<String> performanceIds) {
if (StringUtils.equals(l.getTestType(), TestCaseTestStatus.performance.name())) { for (TestCaseTest l : list) {
performanceIds.add(l.getTestId()); if (StringUtils.equals(l.getTestType(), TestCaseTestStatus.performance.name())) {
} performanceIds.add(l.getTestId());
if (StringUtils.equals(l.getTestType(), TestCaseTestStatus.api.name())) { }
apiCaseIds.add(l.getTestId()); if (StringUtils.equals(l.getTestType(), TestCaseTestStatus.api.name())) {
} apiCaseIds.add(l.getTestId());
if (StringUtils.equals(l.getTestType(), TestCaseTestStatus.automation.name())) { }
scenarioIds.add(l.getTestId()); if (StringUtils.equals(l.getTestType(), TestCaseTestStatus.automation.name())) {
} scenarioIds.add(l.getTestId());
}
try {
relevanceTestCaseTest(apiCaseIds, request.getPlanId(), planTestPlanApiCaseService::relevanceByTestIds);
relevanceTestCaseTest(scenarioIds, request.getPlanId(), planTestPlanScenarioCaseService::relevanceByTestIds);
relevanceTestCaseTest(performanceIds, request.getPlanId(), planTestPlanLoadCaseService::relevanceByTestIds);
} catch (MSException e) {
LogUtil.error(e);
}
});
} }
} }
} }
@ -1321,7 +1326,7 @@ public class TestPlanService {
} }
public void runReportWithExceptionHandle(TestPlanSimpleReportDTO report, Function<TestPlanSimpleReportDTO, Object> getCaseFunc, public void runReportWithExceptionHandle(TestPlanSimpleReportDTO report, Function<TestPlanSimpleReportDTO, Object> getCaseFunc,
BiConsumer<TestPlanSimpleReportDTO, Object> setReportCaseFunc) { BiConsumer<TestPlanSimpleReportDTO, Object> setReportCaseFunc) {
try { try {
// todo 服务调用失败 // todo 服务调用失败
setReportCaseFunc.accept(report, getCaseFunc.apply(report)); setReportCaseFunc.accept(report, getCaseFunc.apply(report));