fix(测试跟踪): 修复测试计划执行后不显示耗时的问题

--bug=1021148 --user=宋天阳 【测试跟踪】测试计划执行后不显示运行耗时
https://www.tapd.cn/55049933/s/1318385
This commit is contained in:
song-tianyang 2022-12-22 10:52:08 +08:00 committed by fit2-zhao
parent ca40ec1332
commit e28b8edeff
1 changed files with 11 additions and 15 deletions

View File

@ -504,9 +504,10 @@ public class TestPlanReportService {
TestPlanReportContentWithBLOBs content = null; TestPlanReportContentWithBLOBs content = null;
try { try {
HttpHeaderUtils.runAsUser(testPlanReport.getCreator()); HttpHeaderUtils.runAsUser(testPlanReport.getCreator());
testPlanReport.setStatus(status); boolean isRerunningTestPlan = BooleanUtils.isTrue(StringUtils.equalsIgnoreCase(testPlanReport.getStatus(), APITestStatus.Rerunning.name()));
content = this.initTestPlanContent(testPlanReport, status); content = this.initTestPlanContent(testPlanReport, status, isRerunningTestPlan);
} catch (Exception e) { } catch (Exception e) {
testPlanReport.setStatus(status);
LogUtil.error("统计测试计划状态失败!", e); LogUtil.error("统计测试计划状态失败!", e);
} finally { } finally {
HttpHeaderUtils.clearUser(); HttpHeaderUtils.clearUser();
@ -518,22 +519,17 @@ public class TestPlanReportService {
return testPlanReport; return testPlanReport;
} }
private TestPlanReportContentWithBLOBs initTestPlanContent(TestPlanReport testPlanReport, String status) throws Exception { private TestPlanReportContentWithBLOBs initTestPlanContent(TestPlanReport testPlanReport, String status, boolean isRerunningTestPlan) throws Exception {
testPlanReport.setStatus(status);
TestPlanReportContentWithBLOBs content = null; TestPlanReportContentWithBLOBs content = null;
//初始化测试计划包含组件信息 //初始化测试计划包含组件信息
int[] componentIndexArr = new int[]{1, 3, 4}; int[] componentIndexArr = new int[]{1, 3, 4};
testPlanReport.setComponents(JSON.toJSONString(componentIndexArr)); testPlanReport.setComponents(JSON.toJSONString(componentIndexArr));
//如果测试案例没有未结束的功能用例则更新最后结束日期
TestPlanTestCaseMapper testPlanTestCaseMapper = CommonBeanFactory.getBean(TestPlanTestCaseMapper.class);
TestPlanTestCaseExample testPlanTestCaseExample = new TestPlanTestCaseExample();
testPlanTestCaseExample.createCriteria().andPlanIdEqualTo(testPlanReport.getTestPlanId()).andStatusNotEqualTo("Prepare");
long endTime = System.currentTimeMillis(); long endTime = System.currentTimeMillis();
long testCaseCount = testPlanTestCaseMapper.countByExample(testPlanTestCaseExample); //原逻辑中要判断包含测试计划功能用例时才会赋予结束时间执行测试计划产生的测试报告它的结束时间感觉没有这种判断必要
boolean updateTestPlanTime = testCaseCount > 0; testPlanReport.setEndTime(endTime);
if (updateTestPlanTime && !StringUtils.equalsAnyIgnoreCase(testPlanReport.getStatus(), APITestStatus.Rerunning.name())) { testPlanReport.setUpdateTime(endTime);
testPlanReport.setEndTime(endTime);
testPlanReport.setUpdateTime(endTime);
}
TestPlanReportContentExample contentExample = new TestPlanReportContentExample(); TestPlanReportContentExample contentExample = new TestPlanReportContentExample();
contentExample.createCriteria().andTestPlanReportIdEqualTo(testPlanReport.getTestPlanId()); contentExample.createCriteria().andTestPlanReportIdEqualTo(testPlanReport.getTestPlanId());
List<TestPlanReportContentWithBLOBs> contents = testPlanReportContentMapper.selectByExampleWithBLOBs(contentExample); List<TestPlanReportContentWithBLOBs> contents = testPlanReportContentMapper.selectByExampleWithBLOBs(contentExample);
@ -550,8 +546,8 @@ public class TestPlanReportService {
testPlanService.checkStatus(testPlanReport.getTestPlanId()); testPlanService.checkStatus(testPlanReport.getTestPlanId());
} }
if (content != null) { if (content != null) {
//更新content表对结束日期 //更新content表对结束日期 重跑的测试计划报告不用更新
if (!StringUtils.equalsAnyIgnoreCase(testPlanReport.getStatus(), APITestStatus.Rerunning.name())) { if (!isRerunningTestPlan) {
content.setStartTime(testPlanReport.getStartTime()); content.setStartTime(testPlanReport.getStartTime());
content.setEndTime(endTime); content.setEndTime(endTime);
} }