diff --git a/backend/src/main/java/io/metersphere/performance/service/PerformanceTestService.java b/backend/src/main/java/io/metersphere/performance/service/PerformanceTestService.java index d342ec32c6..251eda42c1 100644 --- a/backend/src/main/java/io/metersphere/performance/service/PerformanceTestService.java +++ b/backend/src/main/java/io/metersphere/performance/service/PerformanceTestService.java @@ -418,18 +418,28 @@ public class PerformanceTestService { if (forceStop) { reportService.deleteReport(reportId); } else { - LoadTestReport loadTestReport = loadTestReportMapper.selectByPrimaryKey(reportId); - LoadTestWithBLOBs loadTest = loadTestMapper.selectByPrimaryKey(loadTestReport.getTestId()); - final Engine engine = EngineFactory.createEngine(loadTest); - if (engine == null) { - MSException.throwException(String.format("Stop report fail. create engine fail,report ID:%s", reportId)); - } - reportService.stopEngine(loadTest, engine); + stopEngine(reportId); // 停止测试之后设置报告的状态 reportService.updateStatus(reportId, PerformanceTestStatus.Completed.name()); } } + public void stopErrorTest(String reportId) { + stopEngine(reportId); + // 停止测试之后设置报告的状态 + reportService.updateStatus(reportId, PerformanceTestStatus.Error.name()); + } + + private void stopEngine(String reportId) { + LoadTestReport loadTestReport = loadTestReportMapper.selectByPrimaryKey(reportId); + LoadTestWithBLOBs loadTest = loadTestMapper.selectByPrimaryKey(loadTestReport.getTestId()); + final Engine engine = EngineFactory.createEngine(loadTest); + if (engine == null) { + MSException.throwException(String.format("Stop report fail. create engine fail,report ID:%s", reportId)); + } + reportService.stopEngine(loadTest, engine); + } + public List listSchedule(QueryScheduleRequest request) { request.setEnable(true); List schedules = scheduleService.list(request); diff --git a/backend/src/main/java/io/metersphere/performance/service/ReportService.java b/backend/src/main/java/io/metersphere/performance/service/ReportService.java index d3a22c1b26..b50f6d4c23 100644 --- a/backend/src/main/java/io/metersphere/performance/service/ReportService.java +++ b/backend/src/main/java/io/metersphere/performance/service/ReportService.java @@ -241,7 +241,7 @@ public class ReportService { } } - public LoadTestReport getReport(String reportId) { + public LoadTestReportWithBLOBs getReport(String reportId) { return loadTestReportMapper.selectByPrimaryKey(reportId); } diff --git a/backend/src/main/java/io/metersphere/websocket/ReportWebSocket.java b/backend/src/main/java/io/metersphere/websocket/ReportWebSocket.java index 0cca799102..33c072fadf 100644 --- a/backend/src/main/java/io/metersphere/websocket/ReportWebSocket.java +++ b/backend/src/main/java/io/metersphere/websocket/ReportWebSocket.java @@ -1,8 +1,9 @@ package io.metersphere.websocket; -import io.metersphere.base.domain.LoadTestReport; +import io.metersphere.base.domain.LoadTestReportWithBLOBs; import io.metersphere.commons.constants.PerformanceTestStatus; import io.metersphere.commons.utils.LogUtil; +import io.metersphere.performance.service.PerformanceTestService; import io.metersphere.performance.service.ReportService; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Component; @@ -18,12 +19,18 @@ import java.io.IOException; public class ReportWebSocket { private static ReportService reportService; + private static PerformanceTestService performanceTestService; @Resource public void setReportService(ReportService reportService) { ReportWebSocket.reportService = reportService; } + @Resource + public void setPerformanceTestService(PerformanceTestService performanceTestService) { + ReportWebSocket.performanceTestService = performanceTestService; + } + /** * 开启连接的操作 */ @@ -78,12 +85,19 @@ public class ReportWebSocket { public void run() { while (stopMe) { try { - LoadTestReport report = reportService.getReport(reportId); - if (report == null || StringUtils.equalsAny(report.getStatus(), PerformanceTestStatus.Completed.name(), PerformanceTestStatus.Error.name())) { + LoadTestReportWithBLOBs report = reportService.getReport(reportId); + if (report == null || StringUtils.equalsAny(report.getStatus(), PerformanceTestStatus.Completed.name())) { this.stopMe(); session.close(); break; } + if (StringUtils.equals(report.getStatus(), PerformanceTestStatus.Error.name())) { + this.stopMe(); + session.getBasicRemote().sendText("Error: " + report.getDescription()); + performanceTestService.stopErrorTest(reportId); + session.close(); + break; + } if (!session.isOpen()) { return; } diff --git a/frontend/src/business/components/performance/report/PerformanceReportView.vue b/frontend/src/business/components/performance/report/PerformanceReportView.vue index 28ddde3387..0493330f33 100644 --- a/frontend/src/business/components/performance/report/PerformanceReportView.vue +++ b/frontend/src/business/components/performance/report/PerformanceReportView.vue @@ -23,11 +23,11 @@ {{ $t('report.test_execute_again') }} - {{$t('test_track.plan_view.export_report')}} + {{ $t('test_track.plan_view.export_report') }} - + @@ -65,7 +65,8 @@ - + @@ -91,8 +92,7 @@ import MsPerformancePressureConfig from "./components/PerformancePressureConfig" import MsContainer from "../../common/components/MsContainer"; import MsMainContainer from "../../common/components/MsMainContainer"; -import {checkoutTestManagerOrTestUser} from "@/common/js/utils"; -import {exportPdf} from "../../../../common/js/utils"; +import {checkoutTestManagerOrTestUser, exportPdf} from "@/common/js/utils"; import html2canvas from 'html2canvas'; import MsPerformanceReportExport from "./PerformanceReportExport"; @@ -188,7 +188,8 @@ export default { checkReportStatus(status) { switch (status) { case 'Error': - this.$warning(this.$t('report.generation_error')); + // this.$warning(this.$t('report.generation_error')); + this.active = '4'; break; case 'Starting': this.$alert(this.$t('report.start_status')); @@ -240,6 +241,11 @@ export default { }, onMessage(e) { this.$set(this.report, "refresh", e.data); // 触发刷新 + if (e.data.startsWith('Error')) { + this.$set(this.report, "status", 'Error'); + this.$warning(e.data); + return; + } this.$set(this.report, "status", 'Running'); this.status = 'Running'; this.initReportTimeInfo(); @@ -264,7 +270,7 @@ export default { setTimeout(() => { html2canvas(document.getElementById('performanceReportExport'), { scale: 2 - }).then(function(canvas) { + }).then(function (canvas) { exportPdf(name, [canvas]); reset(); }); @@ -332,18 +338,18 @@ export default { diff --git a/frontend/src/business/components/performance/report/PerformanceTestReport.vue b/frontend/src/business/components/performance/report/PerformanceTestReport.vue index 070c62dea2..03500cad62 100644 --- a/frontend/src/business/components/performance/report/PerformanceTestReport.vue +++ b/frontend/src/business/components/performance/report/PerformanceTestReport.vue @@ -180,10 +180,7 @@ export default { this.multipleSelection = val; }, handleEdit(report) { - if (report.status === "Error") { - this.$warning(this.$t('report.generation_error')); - return false - } else if (report.status === "Starting") { + if (report.status === "Starting") { this.$info(this.$t('report.being_generated')) return false } diff --git a/frontend/src/business/components/performance/report/components/TestOverview.vue b/frontend/src/business/components/performance/report/components/TestOverview.vue index d86d6cf26c..e000e5e5ff 100644 --- a/frontend/src/business/components/performance/report/components/TestOverview.vue +++ b/frontend/src/business/components/performance/report/components/TestOverview.vue @@ -114,7 +114,7 @@ export default { this.avgResponseTime = '0'; this.responseTime90 = '0'; this.avgBandwidth = '0'; - this.$warning(this.$t('report.generation_error')); + // this.$warning(this.$t('report.generation_error')); }) this.getLoadChart(); this.getResChart(); diff --git a/frontend/src/business/components/track/plan/view/comonents/test/PerformanceTestResult.vue b/frontend/src/business/components/track/plan/view/comonents/test/PerformanceTestResult.vue index fcbb1c6de3..46b2f6e11e 100644 --- a/frontend/src/business/components/track/plan/view/comonents/test/PerformanceTestResult.vue +++ b/frontend/src/business/components/track/plan/view/comonents/test/PerformanceTestResult.vue @@ -57,24 +57,24 @@