From 8c94e79ba33208926c56aa72a0f25dc560782301 Mon Sep 17 00:00:00 2001 From: song-tianyang Date: Mon, 31 Oct 2022 15:02:16 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=B5=8B=E8=AF=95=E8=B7=9F=E8=B8=AA):=20?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=B5=8B=E8=AF=95=E8=AE=A1=E5=88=92=E6=8A=A5?= =?UTF-8?q?=E5=91=8A=E7=9A=84=E8=AE=A1=E7=AE=97=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1019086 --user=宋天阳 #18478 测试计划关联用例多时(500多个场景用例),查看报告耗时较长(30-60s),建议优化 https://www.tapd.cn/55049933/s/1283179 --- .../plan/service/TestPlanLoadCaseService.java | 1 + .../plan/service/TestPlanReportService.java | 52 ++++++++++++------- .../plan/service/TestPlanService.java | 28 +++++++--- 3 files changed, 54 insertions(+), 27 deletions(-) diff --git a/performance-test/backend/src/main/java/io/metersphere/plan/service/TestPlanLoadCaseService.java b/performance-test/backend/src/main/java/io/metersphere/plan/service/TestPlanLoadCaseService.java index 78a9b96c3f..5d17e408ee 100644 --- a/performance-test/backend/src/main/java/io/metersphere/plan/service/TestPlanLoadCaseService.java +++ b/performance-test/backend/src/main/java/io/metersphere/plan/service/TestPlanLoadCaseService.java @@ -611,6 +611,7 @@ public class TestPlanLoadCaseService { Map config = request.getConfig(); Map loadCaseReportMap = request.getReportIdMap(); if (MapUtils.isEmpty(loadCaseReportMap)) { + loadPlanReport.setLoadAllCases(new ArrayList<>()); return loadPlanReport; } if (ServiceUtils.checkConfigEnable(config, "load")) { diff --git a/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanReportService.java b/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanReportService.java index 1cd7503714..f740ea1095 100644 --- a/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanReportService.java +++ b/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanReportService.java @@ -1,6 +1,7 @@ package io.metersphere.plan.service; +import com.alibaba.fastjson.JSONObject; import io.metersphere.base.domain.*; import io.metersphere.base.mapper.*; import io.metersphere.base.mapper.ext.ExtTestPlanMapper; @@ -557,31 +558,35 @@ public class TestPlanReportService { content.setPassRate(null); extTestPlanReportMapper.setApiBaseCountAndPassRateIsNullById(content.getId()); } - if (content != null) { - //更新content表对结束日期 - if (!StringUtils.equalsAnyIgnoreCase(testPlanReport.getStatus(), APITestStatus.Rerunning.name())) { - content.setStartTime(testPlanReport.getStartTime()); - content.setEndTime(endTime); - } - testPlanReportContentMapper.updateByExampleSelective(content, contentExample); - } - //计算测试计划状态 - if (StringUtils.equalsIgnoreCase(status, TestPlanReportStatus.COMPLETED.name())) { - testPlanReport.setStatus(TestPlanReportStatus.SUCCESS.name()); - HttpHeaderUtils.runAsUser("admin"); - try { - testPlanService.checkStatus(testPlanReport.getTestPlanId()); - } finally { - HttpHeaderUtils.clearUser(); - } - } else { - testPlanReport.setStatus(status); - } + //更新测试计划并发送通知 testPlanReport.setIsApiCaseExecuting(false); testPlanReport.setIsScenarioExecuting(false); testPlanReport.setIsPerformanceExecuting(false); testPlanReport.setIsUiScenarioExecuting(false); + //计算测试计划状态 + + try { + if (StringUtils.equalsIgnoreCase(status, TestPlanReportStatus.COMPLETED.name())) { + testPlanReport.setStatus(TestPlanReportStatus.SUCCESS.name()); + HttpHeaderUtils.runAsUser("admin"); + testPlanService.checkStatus(testPlanReport.getTestPlanId()); + } else { + testPlanReport.setStatus(status); + } + + if (content != null) { + //更新content表对结束日期 + if (!StringUtils.equalsAnyIgnoreCase(testPlanReport.getStatus(), APITestStatus.Rerunning.name())) { + content.setStartTime(testPlanReport.getStartTime()); + content.setEndTime(endTime); + } + this.initTestPlanReportBaseCount(testPlanReport, content); + testPlanReportContentMapper.updateByExampleSelective(content, contentExample); + } + } finally { + HttpHeaderUtils.clearUser(); + } TestPlanExecutionQueueExample testPlanExecutionQueueExample = new TestPlanExecutionQueueExample(); testPlanExecutionQueueExample.createCriteria().andReportIdEqualTo(testPlanReportId); @@ -616,6 +621,13 @@ public class TestPlanReportService { return testPlanReport; } + private void initTestPlanReportBaseCount(TestPlanReport testPlanReport, TestPlanReportContentWithBLOBs reportContent) { + if (testPlanReport != null && reportContent != null) { + TestPlanReportBuildResultDTO reportBuildResultDTO = testPlanService.buildPlanReport(testPlanReport, reportContent); + reportContent.setApiBaseCount(JSONObject.toJSONString(reportBuildResultDTO.getTestPlanSimpleReportDTO())); + } + } + /** * @param planReportId 测试计划报告ID * @param resourceRunMode 资源的运行模式,triggerMode非Scedule可以为null diff --git a/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanService.java b/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanService.java index 379d41e136..4e16ab9f5a 100644 --- a/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanService.java +++ b/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanService.java @@ -1,6 +1,7 @@ package io.metersphere.plan.service; +import com.alibaba.fastjson.JSONObject; import com.google.gson.Gson; import io.metersphere.base.domain.*; import io.metersphere.base.mapper.*; @@ -1263,10 +1264,10 @@ public class TestPlanService { } TestPlanExecuteReportDTO testPlanExecuteReportDTO = testPlanReportService.genTestPlanExecuteReportDTOByTestPlanReportContent(testPlanReportContentWithBLOBs); TestPlanSimpleReportDTO report = null; + boolean apiBaseInfoChanged = false; if (StringUtils.isEmpty(testPlanReportContentWithBLOBs.getApiBaseCount())) { report = getReport(testPlanReport.getTestPlanId(), testPlanExecuteReportDTO); - testPlanReportContentWithBLOBs.setApiBaseCount(JSON.toJSONString(report)); - returnDTO.setApiBaseInfoChanged(true); + apiBaseInfoChanged = true; } else { try { report = JSON.parseObject(testPlanReportContentWithBLOBs.getApiBaseCount(), TestPlanSimpleReportDTO.class); @@ -1275,15 +1276,28 @@ public class TestPlanService { } if (report == null) { report = getReport(testPlanReport.getTestPlanId(), testPlanExecuteReportDTO); - testPlanReportContentWithBLOBs.setApiBaseCount(JSON.toJSONString(report)); - returnDTO.setApiBaseInfoChanged(true); + apiBaseInfoChanged = true; } } - buildFunctionalReport(report, config, testPlanReport.getTestPlanId()); - buildApiReport(report, config, testPlanExecuteReportDTO); - buildLoadReport(report, config, testPlanExecuteReportDTO.getTestPlanLoadCaseIdAndReportIdMap(), false); + if (report.getFunctionAllCases() == null || report.getIssueList() == null) { + buildFunctionalReport(report, config, testPlanReport.getTestPlanId()); + apiBaseInfoChanged = true; + } + if (report.getApiAllCases() == null && report.getScenarioAllCases() == null) { + buildApiReport(report, config, testPlanExecuteReportDTO); + apiBaseInfoChanged = true; + } + if (report.getLoadAllCases() == null) { + buildLoadReport(report, config, testPlanExecuteReportDTO.getTestPlanLoadCaseIdAndReportIdMap(), false); + apiBaseInfoChanged = true; + } buildUiReport(report, config, testPlanReport.getTestPlanId(), testPlanExecuteReportDTO, false); returnDTO.setTestPlanSimpleReportDTO(report); + + if (apiBaseInfoChanged) { + testPlanReportContentWithBLOBs.setApiBaseCount(JSONObject.toJSONString(report)); + returnDTO.setApiBaseInfoChanged(true); + } return returnDTO; } else { returnDTO.setTestPlanSimpleReportDTO(new TestPlanSimpleReportDTO());