fix(测试跟踪): 修复执行测试计划后状态错误

--bug=1015942 --user=刘瑶 【测试跟踪】github#16977,在测试计划列表列表中点击【执行】,完成执行后。该计划当前状态不对:测试进度非100%,但是当前状态为“完成”。 https://www.tapd.cn/55049933/s/1231292
This commit is contained in:
nathan.liu 2022-08-23 16:32:42 +08:00 committed by f2c-ci-robot[bot]
parent a933b92500
commit 18a82f3a7f
3 changed files with 28 additions and 4 deletions

View File

@ -30,6 +30,7 @@ import javax.annotation.Resource;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
@Service
@Transactional
@ -61,8 +62,10 @@ public class TestPlanMessageService {
if (!report.getIsApiCaseExecuting() && !report.getIsPerformanceExecuting() && !report.getIsScenarioExecuting() && !report.getIsUiScenarioExecuting()) {
//更新TestPlan状态为完成
TestPlanWithBLOBs testPlan = testPlanMapper.selectByPrimaryKey(report.getTestPlanId());
if (testPlan != null && !StringUtils.equals(testPlan.getStatus(), TestPlanStatus.Completed.name())) {
testPlan.setStatus(TestPlanStatus.Completed.name());
if (testPlan != null
&& !StringUtils.equalsAny(testPlan.getStatus(), TestPlanStatus.Completed.name(), TestPlanStatus.Finished.name())) {
testPlan.setStatus(calcTestPlanStatusWithPassRate(testPlan));
testPlanService.editTestPlan(testPlan);
}
try {
@ -80,6 +83,27 @@ public class TestPlanMessageService {
}
}
public String calcTestPlanStatusWithPassRate(TestPlanWithBLOBs testPlan) {
try {
// 计算通过率
TestPlanDTOWithMetric testPlanDTOWithMetric = BeanUtils.copyBean(new TestPlanDTOWithMetric(), testPlan);
testPlanService.calcTestPlanRate(Collections.singletonList(testPlanDTOWithMetric));
//测试进度
Double testRate = Optional.ofNullable(testPlanDTOWithMetric.getTestRate()).orElse(0.0);
//通过率
Double passRate = Optional.ofNullable(testPlanDTOWithMetric.getPassRate()).orElse(0.0);
//只有通过率 测试进度 都为100% 才为已完成状态
if (testRate >= 100 && passRate >= 100) {
return TestPlanStatus.Completed.name();
}
} catch (Exception e) {
LogUtil.error("计算通过率失败!", e);
}
return TestPlanStatus.Finished.name();
}
@Async
public void sendMessage(TestPlan testPlan, TestPlanReport testPlanReport, String projectId) {
assert testPlan != null;

@ -1 +1 @@
Subproject commit d82febe01920178e5bcdbdc8364c347e14886d26
Subproject commit 7f4188a8cabb24551e53eaf86bde1fbb5c63564a

@ -1 +1 @@
Subproject commit 99c2acebdffef28a5b1a71299c1552095a2976b3
Subproject commit 70264ea85d57f9951c4655c537011a5db3f4164b