fix(接口测试): 修复测试计划串行后查看未结束的报告页面报错的问题

--bug=1022881 --user=宋天阳 【测试跟踪】github#21679,测试计划间串行执行,测试计划未执行完时点击报告报错
https://www.tapd.cn/55049933/s/1342089
This commit is contained in:
song-tianyang 2023-02-23 15:43:27 +08:00 committed by fit2-zhao
parent 2c588afa93
commit 82bd00dfa5
4 changed files with 46 additions and 36 deletions

View File

@ -254,9 +254,11 @@ public class FileUtils {
}
}
public static void validateFileName(String fileName){
if(StringUtils.isNotBlank(fileName) && fileName.contains(File.separator)){
MSException.throwException(Translator.get("file_name_error"));
public static void validateFileName(String ... fileNames){
for (String fileName : fileNames) {
if(StringUtils.isNotBlank(fileName) && fileName.contains(File.separator)){
MSException.throwException(Translator.get("file_name_error"));
}
}
}

View File

@ -57,9 +57,7 @@ public class ResourceService {
}
public ResponseEntity<FileSystemResource> getUiResultImage(String name, String reportId) {
if (name.contains("/")) {
MSException.throwException(Translator.get("invalid_parameter"));
}
FileUtils.validateFileName(name,reportId);
return getImage(FileUtils.UI_IMAGE_DIR + "/" + reportId + "/" + name);
}

View File

@ -493,25 +493,31 @@ public class TestPlanReportService {
this.initTestPlanReportBaseCount(testPlanReport,content);
testPlanReportContentMapper.updateByExampleSelective(content, contentExample);
}
this.executeTestPlanInQueue(testPlanReportId);
testPlanReportMapper.updateByPrimaryKey(testPlanReport);
}
//发送通知
testPlanMessageService.checkTestPlanStatusAndSendMessage(testPlanReport, content, isSendMessage);
return testPlanReport;
}
TestPlanExecutionQueueExample testPlanExecutionQueueExample = new TestPlanExecutionQueueExample();
testPlanExecutionQueueExample.createCriteria().andReportIdEqualTo(testPlanReportId);
List<TestPlanExecutionQueue> planExecutionQueues = testPlanExecutionQueueMapper.selectByExample(testPlanExecutionQueueExample);
String runMode = null;
String resourceId = null;
if (CollectionUtils.isNotEmpty(planExecutionQueues)) {
runMode = planExecutionQueues.get(0).getRunMode();
resourceId = planExecutionQueues.get(0).getResourceId();
testPlanExecutionQueueMapper.deleteByExample(testPlanExecutionQueueExample);
}
if (runMode != null && StringUtils.equalsIgnoreCase(runMode, RunModeConstants.SERIAL.name()) && resourceId != null) {
TestPlanExecutionQueueExample queueExample = new TestPlanExecutionQueueExample();
queueExample.createCriteria().andReportIdIsNotNull().andResourceIdEqualTo(resourceId);
queueExample.setOrderByClause("`num` ASC");
List<TestPlanExecutionQueue> planExecutionQueueList = testPlanExecutionQueueMapper.selectByExample(queueExample);
if (CollectionUtils.isEmpty(planExecutionQueueList)) {
return testPlanReport;
}
private void executeTestPlanInQueue(String testPlanReportId){
TestPlanExecutionQueueExample testPlanExecutionQueueExample = new TestPlanExecutionQueueExample();
testPlanExecutionQueueExample.createCriteria().andReportIdEqualTo(testPlanReportId);
List<TestPlanExecutionQueue> planExecutionQueues = testPlanExecutionQueueMapper.selectByExample(testPlanExecutionQueueExample);
String runMode = null;
String resourceId = null;
if (CollectionUtils.isNotEmpty(planExecutionQueues)) {
runMode = planExecutionQueues.get(0).getRunMode();
resourceId = planExecutionQueues.get(0).getResourceId();
testPlanExecutionQueueMapper.deleteByExample(testPlanExecutionQueueExample);
}
if (runMode != null && StringUtils.equalsIgnoreCase(runMode, RunModeConstants.SERIAL.name()) && resourceId != null) {
TestPlanExecutionQueueExample queueExample = new TestPlanExecutionQueueExample();
queueExample.createCriteria().andReportIdIsNotNull().andResourceIdEqualTo(resourceId);
queueExample.setOrderByClause("`num` ASC");
List<TestPlanExecutionQueue> planExecutionQueueList = testPlanExecutionQueueMapper.selectByExample(queueExample);
if (CollectionUtils.isNotEmpty(planExecutionQueueList)) {
TestPlanExecutionQueue testPlanExecutionQueue = planExecutionQueueList.get(0);
TestPlanWithBLOBs testPlan = testPlanMapper.selectByPrimaryKey(testPlanExecutionQueue.getTestPlanId());
JSONObject jsonObject = JSONObject.parseObject(testPlan.getRunModeConfig());
@ -520,11 +526,7 @@ public class TestPlanReportService {
runRequest.setReportId(testPlanExecutionQueue.getReportId());
testPlanService.runPlan(runRequest);
}
testPlanReportMapper.updateByPrimaryKey(testPlanReport);
}
//发送通知
testPlanMessageService.checkTestPlanStatusAndSendMessage(testPlanReport, content, isSendMessage);
return testPlanReport;
}
private void initTestPlanReportBaseCount(TestPlanReport testPlanReport, TestPlanReportContentWithBLOBs reportContent) {

View File

@ -130,24 +130,32 @@ export default {
if (this.isShare) {
//
this.result = getShareTestPlanReportContent(this.shareId, this.reportId, (data) => {
this.report = data;
this.report.config = this.getDefaultConfig(this.report);
if(data != null){
this.report = data;
this.report.config = this.getDefaultConfig(this.report);
}
});
} else {
this.result = getTestPlanReportContent(this.reportId, (data) => {
this.report = data;
this.report.config = this.getDefaultConfig(this.report);
if(data != null){
this.report = data;
this.report.config = this.getDefaultConfig(this.report);
}
});
}
} else if (this.isShare) {
this.result = getShareTestPlanReport(this.shareId, this.planId, (data) => {
this.report = data;
this.report.config = this.getDefaultConfig(this.report);
if(data != null){
this.report = data;
this.report.config = this.getDefaultConfig(this.report);
}
});
} else {
this.result = getTestPlanReport(this.planId, (data) => {
this.report = data;
this.report.config = this.getDefaultConfig(this.report);
if(data != null){
this.report = data;
this.report.config = this.getDefaultConfig(this.report);
}
});
}
},