fix(测试计划): 修复了测试计划定时任务执行完成之后发送多个通知(数量根据场景的数量而定)的缺陷,修复了测试计划里的表格拉伸表头造成的表格错乱的问题

修复了测试计划定时任务执行完成之后发送多个通知(数量根据场景的数量而定)的缺陷,修复了测试计划里的表格拉伸表头造成的表格错乱的问题
This commit is contained in:
song-tianyang 2021-06-30 17:12:40 +08:00 committed by 刘瑞斌
parent b65afe97a7
commit 536830f379
6 changed files with 89 additions and 25 deletions

View File

@ -248,20 +248,27 @@ public class ApiScenarioReportService {
List<ScenarioResult> scenarioResultList = result.getScenarios();
List<String> testPlanReportIdList = new ArrayList<>();
StringBuilder scenarioIds = new StringBuilder();
// StringBuilder scenarioIds = new StringBuilder();
StringBuilder scenarioNames = new StringBuilder();
String projectId = null;
String userId = null;
TestResult fullResult = createTestResult(result);
List<String> reportIds = new ArrayList<>();
List<String> scenarioIdList = new ArrayList<>();
for (ScenarioResult scenarioResult : scenarioResultList) {
// 存储场景报告
long startTime = System.currentTimeMillis();
if (CollectionUtils.isNotEmpty(scenarioResult.getRequestResults())) {
startTime = scenarioResult.getRequestResults().get(0).getStartTime();
}
ApiScenarioReport report = editReport(scenarioResult, startTime);
TestResult newResult = createTestResult(result.getTestId(), scenarioResult);
newResult.setConsole(result.getConsole());
scenarioResult.setName(report.getScenarioName());
newResult.addScenario(scenarioResult);
/**
* 测试计划的定时任务场景执行时主键是提前生成的测试报告ID也就是TestResult.id是测试报告ID
* report.getScenarioId中存放的是 TestPlanApiScenario.id:TestPlanReport.id 由于参数限制只得将两个ID拼接起来
@ -292,11 +299,7 @@ public class ApiScenarioReportService {
testPlanApiScenario.setPassRate(passRate);
// 报告详情内容
ApiScenarioReportDetail detail = new ApiScenarioReportDetail();
TestResult newResult = createTestResult(result.getTestId(), scenarioResult);
List<ScenarioResult> scenarioResults = new ArrayList();
scenarioResult.setName(report.getScenarioName());
scenarioResults.add(scenarioResult);
newResult.setScenarios(scenarioResults);
detail.setContent(JSON.toJSONString(newResult).getBytes(StandardCharsets.UTF_8));
detail.setReportId(report.getId());
detail.setProjectId(report.getProjectId());
@ -305,11 +308,10 @@ public class ApiScenarioReportService {
testPlanApiScenario.setReportId(report.getId());
testPlanApiScenario.setUpdateTime(System.currentTimeMillis());
testPlanApiScenarioMapper.updateByPrimaryKeySelective(testPlanApiScenario);
fullResult.addScenario(scenarioResult);
projectId = report.getProjectId();
userId = report.getUserId();
scenarioIds.append(scenarioResult.getName()).append(",");
// scenarioIds.append(scenarioResult.getName()).append(",");
scenarioIdList.add(testPlanApiScenario.getApiScenarioId());
scenarioNames.append(report.getName()).append(",");
lastReport = report;
@ -319,7 +321,7 @@ public class ApiScenarioReportService {
// margeReport(result, scenarioIds, scenarioNames, runMode, projectId, userId, reportIds);
TestPlanReportService testPlanReportService = CommonBeanFactory.getBean(TestPlanReportService.class);
testPlanReportService.updateReport(testPlanReportIdList, runMode, lastReport.getTriggerMode());
testPlanReportService.updateReport(testPlanReportIdList, runMode, lastReport.getTriggerMode(),scenarioIdList);
return lastReport;
}

View File

@ -71,7 +71,7 @@ public class TestPlanReportController {
String reportId = UUID.randomUUID().toString();
TestPlanReportSaveRequest saveRequest = new TestPlanReportSaveRequest(reportId,planId,userId,ReportTriggerMode.API.name());
TestPlanReport report = testPlanReportService.genTestPlanReport(saveRequest);
testPlanReportService.countReportByTestPlanReportId(report.getId(),null, ReportTriggerMode.API.name());
testPlanReportService.countReportByTestPlanReportId(report.getId(),null, ReportTriggerMode.API.name(),null);
}
@GetMapping("/saveTestPlanReport/{planId}/{triggerMode}")
@ -80,7 +80,7 @@ public class TestPlanReportController {
String reportId = UUID.randomUUID().toString();
TestPlanReportSaveRequest saveRequest = new TestPlanReportSaveRequest(reportId,planId,userId,triggerMode);
TestPlanReport report = testPlanReportService.genTestPlanReport(saveRequest);
testPlanReportService.countReportByTestPlanReportId(report.getId(),null, triggerMode);
testPlanReportService.countReportByTestPlanReportId(report.getId(),null, triggerMode,null);
return "success";
}
}

View File

@ -12,5 +12,6 @@ public class TestCaseReportAdvanceStatusResultDTO {
private List<TestCaseReportStatusResultDTO> apiResult;
private List<TestCaseReportStatusResultDTO> scenarioResult;
private List<TestCaseReportStatusResultDTO> loadResult;
private List<String> executedScenarioIds;
}

View File

@ -79,14 +79,14 @@ public class TestPlanReportService {
}
/**
* @param reportId 报告ID(外部传入
* @param planId 测试计划ID
* @param userId 用户ID
* @param triggerMode 执行方式
* @param countResources 是否统计资源-false的话 下面三个不同资源是否运行则由参数决定 true的话则由统计后的结果决定
* @param apiCaseIsExecuting 接口案例是否执行中
* @param scenarioIsExecuting 场景案例是否执行中
* @param performanceIsExecuting 性能案例是否执行中
* saveRequest.reportId 报告ID(外部传入
* saveRequest.planId 测试计划ID
* saveRequest.userId 用户ID
* saveRequest.triggerMode 执行方式
* saveRequest.countResources 是否统计资源-false的话 下面三个不同资源是否运行则由参数决定 true的话则由统计后的结果决定
* saveRequest.apiCaseIsExecuting 接口案例是否执行中
* saveRequest.scenarioIsExecuting 场景案例是否执行中
* saveRequest.performanceIsExecuting 性能案例是否执行中
* @return
*/
public TestPlanReport genTestPlanReport(TestPlanReportSaveRequest saveRequest) {
@ -215,7 +215,13 @@ public class TestPlanReportService {
public synchronized void updateReport(List<String> testPlanReportIdList, String runMode, String triggerMode) {
for (String planReportId : testPlanReportIdList) {
this.countReportByTestPlanReportId(planReportId, runMode, triggerMode);
this.countReportByTestPlanReportId(planReportId, runMode, triggerMode,null);
}
}
public synchronized void updateReport(List<String> testPlanReportIdList, String runMode, String triggerMode,List<String> scenarioIdList) {
for (String planReportId : testPlanReportIdList) {
this.countReportByTestPlanReportId(planReportId, runMode, triggerMode,scenarioIdList);
}
}
@ -233,7 +239,7 @@ public class TestPlanReportService {
* @param resourceRunMode 资源的运行模式,triggerMode非Scedule可以为null
* @param triggerMode 触发方式 ReportTriggerMode.enum
*/
public void countReportByTestPlanReportId(String planReportId, String resourceRunMode, String triggerMode) {
public void countReportByTestPlanReportId(String planReportId, String resourceRunMode, String triggerMode,List<String> scenarioIdList) {
TestPlanReport testPlanReport = testPlanReportMapper.selectByPrimaryKey(planReportId);
QueryTestPlanRequest queryTestPlanRequest = new QueryTestPlanRequest();
@ -318,6 +324,39 @@ public class TestPlanReportService {
TestPlanReportDataWithBLOBs testPlanReportData = null;
if (!testPlanReportDataList.isEmpty()) {
testPlanReportData = testPlanReportDataList.get(0);
if (CollectionUtils.isNotEmpty(scenarioIdList)
&&StringUtils.equalsAny(triggerMode, ReportTriggerMode.SCHEDULE.name(), ReportTriggerMode.API.name())
&& StringUtils.equalsAny(resourceRunMode, ApiRunMode.SCHEDULE_SCENARIO_PLAN.name(), ApiRunMode.JENKINS_SCENARIO_PLAN.name())) {
try{
List<String> scenarioListArr = JSONArray.parseArray(testPlanReportData.getScenarioInfo(),String.class);
TestCaseReportAdvanceStatusResultDTO savedDTO = JSONObject.parseObject(testPlanReportData.getExecuteResult(),TestCaseReportAdvanceStatusResultDTO.class);
List<String> executeScenarioList = new ArrayList<>();
if(savedDTO != null){
if(savedDTO.getExecutedScenarioIds() != null){
executeScenarioList = savedDTO.getExecutedScenarioIds();
}
}
for (String scenarioId : scenarioIdList) {
if (!executeScenarioList.contains(scenarioId)) {
executeScenarioList.add(scenarioId);
}
}
if(testCaseReportMetricDTO.getExecuteResult() == null){
TestCaseReportAdvanceStatusResultDTO executeResultDTO = new TestCaseReportAdvanceStatusResultDTO();
testCaseReportMetricDTO.setExecuteResult(executeResultDTO);
}
testCaseReportMetricDTO.getExecuteResult().setExecutedScenarioIds(executeScenarioList);
if(!CollectionUtils.isEqualCollection(scenarioListArr,executeScenarioList)){
testPlanReport.setIsScenarioExecuting(true);
}
}catch (Exception e){
e.printStackTrace();
}
}
//统计执行的场景ID
testPlanReportData.setExecuteResult(JSONObject.toJSONString(testCaseReportMetricDTO.getExecuteResult()));
testPlanReportData.setFailurTestCases(JSONObject.toJSONString(testCaseReportMetricDTO.getFailureTestCases()));
testPlanReportData.setModuleExecuteResult(JSONArray.toJSONString(testCaseReportMetricDTO.getModuleExecuteResult()));

View File

@ -15,6 +15,7 @@
<el-table v-loading="result.loading" ref="table"
border
:data="tableData" row-key="id" class="test-content adjust-table ms-select-all-fixed"
@header-dragend="tableHeaderDragend"
@select-all="handleSelectAll"
@filter-change="filter"
@sort-change="sort"
@ -46,7 +47,7 @@
column-key="priority"
:label="$t('test_track.case.priority')"
show-overflow-tooltip
min-width="120"
min-width="120px"
:key="index">
<template v-slot:default="scope">
<priority-table-item :value="scope.row.priority"/>
@ -679,6 +680,16 @@ export default {
//
this.selectDataCounts = getSelectDataCounts(this.condition, this.total, this.selectRows);
},
tableHeaderDragend(newWidth, oldWidth, column, event){
if(column){
if(column.minWidth){
let minWidth = column.minWidth;
if(minWidth > newWidth){
column.width = minWidth;
}
}
}
},
},
};
</script>

View File

@ -12,6 +12,7 @@
border :data="tableData" class="test-content adjust-table ms-select-all-fixed"
@select-all="handleSelectAll"
@sort-change="sort"
@header-dragend="tableHeaderDragend"
@filter-change="filter"
:height="screenHeight"
@select="handleSelect">
@ -69,7 +70,7 @@
</el-table-column>
<el-table-column v-if="item.id == 'updateTime'"
prop="updateTime"
min-width="120px"
min-width="160px"
sortable="custom"
:label="$t('api_test.automation.update_time')" width="180" :key="index">
<template v-slot:default="scope">
@ -522,6 +523,16 @@ export default {
//
this.selectDataCounts = getSelectDataCounts(this.condition, this.total, this.selectRows);
},
tableHeaderDragend(newWidth, oldWidth, column, event){
if(column){
if(column.minWidth){
let minWidth = column.minWidth;
if(minWidth > newWidth){
column.width = minWidth;
}
}
}
},
}
}
</script>