This commit is contained in:
chenjianxing 2020-11-04 14:26:39 +08:00
commit c482bdc985
10 changed files with 82 additions and 55 deletions

View File

@ -418,6 +418,19 @@ public class PerformanceTestService {
if (forceStop) {
reportService.deleteReport(reportId);
} else {
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);
@ -425,9 +438,6 @@ public class PerformanceTestService {
MSException.throwException(String.format("Stop report fail. create engine failreport ID%s", reportId));
}
reportService.stopEngine(loadTest, engine);
// 停止测试之后设置报告的状态
reportService.updateStatus(reportId, PerformanceTestStatus.Completed.name());
}
}
public List<ScheduleDao> listSchedule(QueryScheduleRequest request) {

View File

@ -241,7 +241,7 @@ public class ReportService {
}
}
public LoadTestReport getReport(String reportId) {
public LoadTestReportWithBLOBs getReport(String reportId) {
return loadTestReportMapper.selectByPrimaryKey(reportId);
}

View File

@ -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;
}

View File

@ -23,7 +23,7 @@
{{ $t('report.test_execute_again') }}
</el-button>
<el-button :disabled="isReadOnly" type="info" plain size="mini" @click="handleExport(reportName)">
{{$t('test_track.plan_view.export_report')}}
{{ $t('test_track.plan_view.export_report') }}
</el-button>
<!--<el-button :disabled="isReadOnly" type="warning" plain size="mini">-->
@ -65,7 +65,8 @@
</el-tabs>
</div>
<ms-performance-report-export :title="reportName" id="performanceReportExport" v-show="reportExportVisible" :report="report"/>
<ms-performance-report-export :title="reportName" id="performanceReportExport" v-show="reportExportVisible"
:report="report"/>
</el-card>
<el-dialog :title="$t('report.test_stop_now_confirm')" :visible.sync="dialogFormVisible" width="30%">
@ -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 {
<style scoped>
.ms-report-view-btns {
.ms-report-view-btns {
margin-top: 15px;
}
}
.ms-report-time-desc {
.ms-report-time-desc {
text-align: left;
display: block;
color: #5C7878;
}
}
.report-export .el-card {
.report-export .el-card {
margin-bottom: 15px;
}
}
</style>

View File

@ -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
}

View File

@ -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();

View File

@ -57,14 +57,14 @@
</template>
<script>
import MsMainContainer from "../../../../../common/components/MsMainContainer";
import MsContainer from "../../../../../common/components/MsContainer";
import LogDetails from "../../../../../performance/report/components/LogDetails";
import ErrorLog from "../../../../../performance/report/components/ErrorLog";
import RequestStatistics from "../../../../../performance/report/components/RequestStatistics";
import TestOverview from "../../../../../performance/report/components/TestOverview";
import MsMainContainer from "../../../../../common/components/MsMainContainer";
import MsContainer from "../../../../../common/components/MsContainer";
import LogDetails from "../../../../../performance/report/components/LogDetails";
import ErrorLog from "../../../../../performance/report/components/ErrorLog";
import RequestStatistics from "../../../../../performance/report/components/RequestStatistics";
import TestOverview from "../../../../../performance/report/components/TestOverview";
export default {
export default {
name: "PerformanceTestResult",
components: {
TestOverview,
@ -145,7 +145,7 @@
}
switch (this.report.status) {
case 'Error':
this.$warning(this.$t('report.generation_error'));
// this.$warning(this.$t('report.generation_error'));
break;
case 'Starting':
this.$warning(this.$t('report.start_status'));

View File

@ -348,7 +348,7 @@ export default {
test_execute_again: 'Test Execute Again',
export: 'Export',
compare: 'Compare',
generation_error: 'Report generation error, cannot be viewed!',
generation_error: 'Report generation error, unable to view, please check log details!',
being_generated: 'Report is being generated...',
delete_confirm: 'Confirm delete: ',
start_status: 'The test is in the beginning state, we will automatically display it on the page after we generate the report!',

View File

@ -347,7 +347,7 @@ export default {
test_execute_again: '再次执行',
export: '导出',
compare: '比较',
generation_error: '报告生成错误,无法查看!',
generation_error: '报告生成错误, 无法查看, 请检查日志详情!',
being_generated: '报告正在生成中...',
delete_confirm: '确认删除报告: ',
start_status: '测试处于开始状态, 我们生成报告后会自动展示到页面上!',

View File

@ -349,7 +349,7 @@ export default {
test_execute_again: '再次執行',
export: '導出',
compare: '比較',
generation_error: '報告生成錯誤,無法查看!',
generation_error: '報告生成錯誤, 無法查看, 請檢查日誌詳情!',
being_generated: '報告正在生成中...',
delete_confirm: '確認刪除報告: ',
start_status: '測試處於開始狀態, 我們生成報告後會自動展示到頁面上!',