fix(性能测试): 修复报告页面下载zip都是最新文件的问题

--bug=1013315 --user=刘瑞斌 【性能测试】github#13720,性能测试一个任务多个报告,历史的报告下载的也是最新的 jmx 执行文件 https://www.tapd.cn/55049933/s/1161694

Closes #13720
This commit is contained in:
CaptainB 2022-05-21 15:57:36 +08:00 committed by f2c-ci-robot[bot]
parent 87a45eebd8
commit 983de4b3e4
2 changed files with 25 additions and 1 deletions

View File

@ -82,6 +82,8 @@ public class PerformanceReportService {
private RedissonClient redissonClient; private RedissonClient redissonClient;
@Resource @Resource
private ProjectMapper projectMapper; private ProjectMapper projectMapper;
@Resource
private LoadTestReportFileMapper loadTestReportFileMapper;
public List<ReportDTO> getRecentReportList(ReportRequest request) { public List<ReportDTO> getRecentReportList(ReportRequest request) {
List<OrderRequest> orders = new ArrayList<>(); List<OrderRequest> orders = new ArrayList<>();
@ -152,6 +154,11 @@ public class PerformanceReportService {
example.createCriteria().andReportIdEqualTo(reportId); example.createCriteria().andReportIdEqualTo(reportId);
loadTestReportDetailMapper.deleteByExample(example); loadTestReportDetailMapper.deleteByExample(example);
// delete load_test_report_file
LoadTestReportFileExample loadTestReportFileExample = new LoadTestReportFileExample();
loadTestReportFileExample.createCriteria().andReportIdEqualTo(reportId);
loadTestReportFileMapper.deleteByExample(loadTestReportFileExample);
// delete load_test_report_log // delete load_test_report_log
LoadTestReportLogExample loadTestReportLogExample = new LoadTestReportLogExample(); LoadTestReportLogExample loadTestReportLogExample = new LoadTestReportLogExample();
loadTestReportLogExample.createCriteria().andReportIdEqualTo(reportId); loadTestReportLogExample.createCriteria().andReportIdEqualTo(reportId);

View File

@ -130,6 +130,8 @@ public class PerformanceTestService {
private ExtProjectVersionMapper extProjectVersionMapper; private ExtProjectVersionMapper extProjectVersionMapper;
@Resource @Resource
private RedissonClient redissonClient; private RedissonClient redissonClient;
@Resource
private LoadTestReportFileMapper loadTestReportFileMapper;
public List<LoadTestDTO> list(QueryTestPlanRequest request) { public List<LoadTestDTO> list(QueryTestPlanRequest request) {
request.setOrders(ServiceUtils.getDefaultSortOrder(request.getOrders())); request.setOrders(ServiceUtils.getDefaultSortOrder(request.getOrders()));
@ -509,12 +511,14 @@ public class PerformanceTestService {
reportResult.setReportValue("Ready"); // 初始化一个 result_status, 这个值用在data-streaming中 reportResult.setReportValue("Ready"); // 初始化一个 result_status, 这个值用在data-streaming中
loadTestReportResultMapper.insertSelective(reportResult); loadTestReportResultMapper.insertSelective(reportResult);
// 保存标记 // 保存标记
LoadTestReportResult rr = new LoadTestReportResult(); LoadTestReportResult rr = new LoadTestReportResult();
rr.setId(UUID.randomUUID().toString()); rr.setId(UUID.randomUUID().toString());
rr.setReportId(testReport.getId()); rr.setReportId(testReport.getId());
rr.setReportKey(ReportKeys.VumProcessedStatus.name()); rr.setReportKey(ReportKeys.VumProcessedStatus.name());
rr.setReportValue(VumProcessedStatus.NOT_PROCESSED); // 避免测试运行出错时对报告重复处理vum_used值 rr.setReportValue(VumProcessedStatus.NOT_PROCESSED); // 避免测试运行出错时对报告重复处理vum_used值
loadTestReportResultMapper.insertSelective(rr); loadTestReportResultMapper.insertSelective(rr);
// 保存执行当时的file
saveLoadTestReportFiles(testReport);
// 检查配额 // 检查配额
this.checkLoadQuota(testReport, engine); this.checkLoadQuota(testReport, engine);
return testReport.getId(); return testReport.getId();
@ -532,6 +536,19 @@ public class PerformanceTestService {
} }
} }
private void saveLoadTestReportFiles(LoadTestReport report) {
LoadTestFileExample example = new LoadTestFileExample();
example.createCriteria().andTestIdEqualTo(report.getTestId());
List<LoadTestFile> files = loadTestFileMapper.selectByExample(example);
files.forEach(f -> {
LoadTestReportFile record = new LoadTestReportFile();
record.setFileId(f.getFileId());
record.setSort(f.getSort());
record.setReportId(report.getId());
loadTestReportFileMapper.insert(record);
});
}
private void checkLoadQuota(LoadTestReportWithBLOBs testReport, Engine engine) { private void checkLoadQuota(LoadTestReportWithBLOBs testReport, Engine engine) {
RunTestPlanRequest checkRequest = new RunTestPlanRequest(); RunTestPlanRequest checkRequest = new RunTestPlanRequest();
QuotaService quotaService = CommonBeanFactory.getBean(QuotaService.class); QuotaService quotaService = CommonBeanFactory.getBean(QuotaService.class);