From 687267923aac471004c82e304c5b44c2b28a9a8f Mon Sep 17 00:00:00 2001 From: CaptainB Date: Wed, 23 Feb 2022 13:24:34 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E6=80=A7=E8=83=BD=E6=B5=8B=E8=AF=95):?= =?UTF-8?q?=20=E4=BF=AE=E6=94=B9=E6=80=A7=E8=83=BD=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E6=8A=A5=E5=91=8A=E9=A1=B5=E9=9D=A2=E6=8A=A5=E9=94=99=E7=9A=84?= =?UTF-8?q?=E5=BC=B9=E6=A1=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1010368 --user=刘瑞斌 [性能测试] github#10684性能执行过程中,执行时长,开始时间显示异常 https://www.tapd.cn/55049933/s/1108562 Closes #10684 --- .../service/PerformanceReportService.java | 51 +++++++++++++------ .../report/PerformanceReportView.vue | 2 +- 2 files changed, 37 insertions(+), 16 deletions(-) diff --git a/backend/src/main/java/io/metersphere/performance/service/PerformanceReportService.java b/backend/src/main/java/io/metersphere/performance/service/PerformanceReportService.java index 3f2fe29e29..9d40ce6266 100644 --- a/backend/src/main/java/io/metersphere/performance/service/PerformanceReportService.java +++ b/backend/src/main/java/io/metersphere/performance/service/PerformanceReportService.java @@ -43,7 +43,10 @@ import javax.servlet.http.HttpServletResponse; import java.io.InputStream; import java.io.OutputStream; import java.text.SimpleDateFormat; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; import java.util.stream.Collectors; @Service @@ -173,31 +176,41 @@ public class PerformanceReportService { } public List getReportStatistics(String id) { - checkReportStatus(id); + if (isReportError(id)) { + return Collections.emptyList(); + } String reportValue = getContent(id, ReportKeys.RequestStatistics); return JSON.parseArray(reportValue, Statistics.class); } public List getReportErrors(String id) { - checkReportStatus(id); + if (isReportError(id)) { + return Collections.emptyList(); + } String content = getContent(id, ReportKeys.Errors); return JSON.parseArray(content, Errors.class); } public List getReportErrorsTOP5(String id) { - checkReportStatus(id); + if (isReportError(id)) { + return Collections.emptyList(); + } String content = getContent(id, ReportKeys.ErrorsTop5); return JSON.parseArray(content, ErrorsTop5.class); } public TestOverview getTestOverview(String id) { - checkReportStatus(id); + if (isReportError(id)) { + return new TestOverview(); + } String content = getContent(id, ReportKeys.Overview); return JSON.parseObject(content, TestOverview.class); } public ReportTimeInfo getReportTimeInfo(String id) { - checkReportStatus(id); + if (isReportError(id)) { + return new ReportTimeInfo(); + } String content = getContent(id, ReportKeys.TimeInfo); try { return JSON.parseObject(content, ReportTimeInfo.class); @@ -221,26 +234,28 @@ public class PerformanceReportService { } public List getLoadChartData(String id) { - checkReportStatus(id); + if (isReportError(id)) { + return Collections.emptyList(); + } String content = getContent(id, ReportKeys.LoadChart); return JSON.parseArray(content, ChartsData.class); } public List getResponseTimeChartData(String id) { - checkReportStatus(id); + if (isReportError(id)) { + return Collections.emptyList(); + } String content = getContent(id, ReportKeys.ResponseTimeChart); return JSON.parseArray(content, ChartsData.class); } - public void checkReportStatus(String reportId) { + public boolean isReportError(String reportId) { LoadTestReport loadTestReport = loadTestReportMapper.selectByPrimaryKey(reportId); String reportStatus = ""; if (loadTestReport != null) { reportStatus = loadTestReport.getStatus(); } - if (StringUtils.equals(PerformanceTestStatus.Error.name(), reportStatus)) { - MSException.throwException("Report generation error!"); - } + return StringUtils.equals(PerformanceTestStatus.Error.name(), reportStatus); } public LoadTestReportWithBLOBs getLoadTestReport(String id) { @@ -329,13 +344,17 @@ public class PerformanceReportService { } public List getErrorChartData(String id) { - checkReportStatus(id); + if (isReportError(id)) { + return Collections.emptyList(); + } String content = getContent(id, ReportKeys.ErrorsChart); return JSON.parseArray(content, ChartsData.class); } public List getResponseCodeChartData(String id) { - checkReportStatus(id); + if (isReportError(id)) { + return Collections.emptyList(); + } String content = getContent(id, ReportKeys.ResponseCodeChart); return JSON.parseArray(content, ChartsData.class); } @@ -423,7 +442,9 @@ public class PerformanceReportService { } public List getReportChart(String reportKey, String reportId) { - checkReportStatus(reportId); + if (isReportError(reportId)) { + return Collections.emptyList(); + } try { String content = getContent(reportId, ReportKeys.valueOf(reportKey)); return JSON.parseArray(content, ChartsData.class); diff --git a/frontend/src/business/components/performance/report/PerformanceReportView.vue b/frontend/src/business/components/performance/report/PerformanceReportView.vue index e967248767..5ab6e659fa 100644 --- a/frontend/src/business/components/performance/report/PerformanceReportView.vue +++ b/frontend/src/business/components/performance/report/PerformanceReportView.vue @@ -330,7 +330,7 @@ export default { this.$set(this.report, "refresh", e.data); // 触发刷新 if (e.data.startsWith('Error')) { this.$set(this.report, "status", 'Error'); - this.$warning(e.data); + this.$error(e.data); return; } this.$set(this.report, "status", 'Running');