fix(测试跟踪): 测试计划执行结束后没有更新测试计划状态

--bug=1018441 --user=陈建星 【测试跟踪】测试计划列表,测试进度和状态对应不上 https://www.tapd.cn/55049933/s/1271996
This commit is contained in:
chenjianxing 2022-10-22 14:06:13 +08:00 committed by jianxing
parent 39f1c28bb3
commit 44bece59ce
8 changed files with 141 additions and 69 deletions

View File

@ -2,9 +2,11 @@ package io.metersphere.dto;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ServiceDTO {
private String serviceId;
private int port;

View File

@ -26,6 +26,7 @@ import io.metersphere.plan.utils.TestPlanStatusCalculator;
import io.metersphere.request.report.QueryTestPlanReportRequest;
import io.metersphere.service.BaseUserService;
import io.metersphere.service.ServiceUtils;
import io.metersphere.utils.DiscoveryUtil;
import io.metersphere.xpack.track.dto.IssuesDao;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
@ -240,7 +241,7 @@ public class TestPlanReportService {
public TestPlanScheduleReportInfoDTO genTestPlanReportBySchedule(String planReportId, String planId, String userId, String triggerMode, RunModeConfigDTO runModeConfigDTO) {
TestPlanReport testPlanReport = this.getTestPlanReport(planReportId);
TestPlanScheduleReportInfoDTO returnDTO = new TestPlanScheduleReportInfoDTO();
TestPlanReportRunInfoDTO runInfoDTO = null; // todo 可以为null
TestPlanReportRunInfoDTO runInfoDTO = null;
if (testPlanReport != null) {
returnDTO.setTestPlanReport(testPlanReport);
}
@ -253,50 +254,58 @@ public class TestPlanReportService {
.setTriggerMode(triggerMode)
.build();
Set<String> serviceIdSet = DiscoveryUtil.getServiceIdSet();
try {
// todo 远程调用失败处理逻辑
TestPlanApiReportInfoDTO testPlanApiReportInfoDTO = planTestPlanScenarioCaseService.genApiReportInfoForSchedule(planId, runModeConfigDTO);
Map<String, String> planScenarioIdMap = testPlanApiReportInfoDTO.getPlanScenarioIdMap();
Map<String, String> planApiCaseIdMap = testPlanApiReportInfoDTO.getPlanApiCaseIdMap();
runInfoDTO = testPlanApiReportInfoDTO.getRunInfoDTO();
if (serviceIdSet.contains(MicroServiceName.API_TEST)) {
// todo 远程调用失败处理逻辑
TestPlanApiReportInfoDTO testPlanApiReportInfoDTO = planTestPlanScenarioCaseService.genApiReportInfoForSchedule(planId, runModeConfigDTO);
Map<String, String> planScenarioIdMap = testPlanApiReportInfoDTO.getPlanScenarioIdMap();
Map<String, String> planApiCaseIdMap = testPlanApiReportInfoDTO.getPlanApiCaseIdMap();
runInfoDTO = testPlanApiReportInfoDTO.getRunInfoDTO();
saveRequest.setApiCaseIsExecuting(!planApiCaseIdMap.isEmpty());
saveRequest.setScenarioIsExecuting(!planScenarioIdMap.isEmpty());
saveRequest.setApiCaseIdMap(planApiCaseIdMap);
saveRequest.setScenarioIdMap(planScenarioIdMap);
saveRequest.setApiCaseIsExecuting(!planApiCaseIdMap.isEmpty());
saveRequest.setScenarioIsExecuting(!planScenarioIdMap.isEmpty());
saveRequest.setApiCaseIdMap(planApiCaseIdMap);
saveRequest.setScenarioIdMap(planScenarioIdMap);
returnDTO.setPlanScenarioIdMap(planScenarioIdMap);
returnDTO.setApiTestCaseDataMap(planApiCaseIdMap);
returnDTO.setPlanScenarioIdMap(planScenarioIdMap);
returnDTO.setApiTestCaseDataMap(planApiCaseIdMap);
}
} catch (Exception e) {
LogUtil.error(e);
}
try {
// todo 远程调用失败处理逻辑
Map<String, String> performanceIdMap = new LinkedHashMap<>();
List<TestPlanLoadCaseDTO> testPlanLoadCaseDTOList = planTestPlanLoadCaseService.list(planId);
for (TestPlanLoadCaseDTO dto : testPlanLoadCaseDTOList) {
performanceIdMap.put(dto.getId(), dto.getLoadCaseId());
}
saveRequest.setPerformanceIsExecuting(!performanceIdMap.isEmpty());
saveRequest.setPerformanceIdMap(performanceIdMap);
if (serviceIdSet.contains(MicroServiceName.PERFORMANCE_TEST)) {
// todo 远程调用失败处理逻辑
Map<String, String> performanceIdMap = new LinkedHashMap<>();
List<TestPlanLoadCaseDTO> testPlanLoadCaseDTOList = planTestPlanLoadCaseService.list(planId);
for (TestPlanLoadCaseDTO dto : testPlanLoadCaseDTOList) {
performanceIdMap.put(dto.getId(), dto.getLoadCaseId());
}
saveRequest.setPerformanceIsExecuting(!performanceIdMap.isEmpty());
saveRequest.setPerformanceIdMap(performanceIdMap);
returnDTO.setPerformanceIdMap(performanceIdMap);
returnDTO.setPerformanceIdMap(performanceIdMap);
}
} catch (Exception e) {
LogUtil.error(e);
}
try {
// todo 远程调用失败处理逻辑
Map<String, String> uiScenarioIdMap = new LinkedHashMap<>();
List<TestPlanUiScenario> testPlanUiScenarioList = planTestPlanUiScenarioCaseService.list(planId);
for (TestPlanUiScenario dto : testPlanUiScenarioList) {
uiScenarioIdMap.put(dto.getId(), dto.getUiScenarioId());
}
saveRequest.setUiScenarioIsExecuting(!uiScenarioIdMap.isEmpty());
saveRequest.setUiScenarioIdMap(uiScenarioIdMap);
if (serviceIdSet.contains(MicroServiceName.UI_TEST)) {
// todo 远程调用失败处理逻辑
Map<String, String> uiScenarioIdMap = new LinkedHashMap<>();
List<TestPlanUiScenario> testPlanUiScenarioList = planTestPlanUiScenarioCaseService.list(planId);
for (TestPlanUiScenario dto : testPlanUiScenarioList) {
uiScenarioIdMap.put(dto.getId(), dto.getUiScenarioId());
}
saveRequest.setUiScenarioIsExecuting(!uiScenarioIdMap.isEmpty());
saveRequest.setUiScenarioIdMap(uiScenarioIdMap);
returnDTO.setUiScenarioIdMap(uiScenarioIdMap);
returnDTO.setUiScenarioIdMap(uiScenarioIdMap);
}
} catch (Exception e) {
LogUtil.error(e);
}
@ -348,29 +357,34 @@ public class TestPlanReportService {
testPlanReport.setRunInfo(JSON.toJSONString(runInfoDTO));
}
Set<String> serviceIdSet = DiscoveryUtil.getServiceIdSet();
if (saveRequest.isCountResources()) {
String planId = saveRequest.getPlanId();
try {
// todo 远程调用失败处理逻辑
testPlanReport.setIsApiCaseExecuting(planTestPlanApiCaseService.isCaseExecuting(planId));
if (serviceIdSet.contains(MicroServiceName.API_TEST)) {
// todo 远程调用失败处理逻辑
testPlanReport.setIsApiCaseExecuting(planTestPlanApiCaseService.isCaseExecuting(planId));
testPlanReport.setIsScenarioExecuting(planTestPlanScenarioCaseService.isCaseExecuting(planId));
}
} catch (Exception e) {
LogUtil.error(e);
}
try {
// todo 远程调用失败处理逻辑
testPlanReport.setIsScenarioExecuting(planTestPlanScenarioCaseService.isCaseExecuting(planId));
if (serviceIdSet.contains(MicroServiceName.UI_TEST)) {
// todo 远程调用失败处理逻辑
testPlanReport.setIsUiScenarioExecuting(planTestPlanUiScenarioCaseService.isCaseExecuting(planId));
}
} catch (Exception e) {
LogUtil.error(e);
}
try {
// todo 远程调用失败处理逻辑
testPlanReport.setIsUiScenarioExecuting(planTestPlanUiScenarioCaseService.isCaseExecuting(planId));
} catch (Exception e) {
LogUtil.error(e);
}
try {
// todo 远程调用失败处理逻辑
testPlanReport.setIsPerformanceExecuting(planTestPlanLoadCaseService.isCaseExecuting(planId, testPlan.getProjectId()));
if (serviceIdSet.contains(MicroServiceName.PERFORMANCE_TEST)) {
// todo 远程调用失败处理逻辑
testPlanReport.setIsPerformanceExecuting(planTestPlanLoadCaseService.isCaseExecuting(planId, testPlan.getProjectId()));
}
} catch (Exception e) {
LogUtil.error(e);
}
@ -554,6 +568,12 @@ public class TestPlanReportService {
//计算测试计划状态
if (StringUtils.equalsIgnoreCase(status, TestPlanReportStatus.COMPLETED.name())) {
testPlanReport.setStatus(TestPlanReportStatus.SUCCESS.name());
HttpHeaderUtils.runAsUser("admin");
try {
testPlanService.checkStatus(testPlanReport.getTestPlanId());
} finally {
HttpHeaderUtils.clearUser();
}
} else {
testPlanReport.setStatus(status);
}

View File

@ -44,6 +44,7 @@ import io.metersphere.plan.service.remote.ui.PlanUiAutomationService;
import io.metersphere.plan.utils.TestPlanRequestUtil;
import io.metersphere.request.ScheduleRequest;
import io.metersphere.service.*;
import io.metersphere.utils.DiscoveryUtil;
import io.metersphere.utils.LoggerUtil;
import io.metersphere.xpack.track.dto.IssuesDao;
import org.apache.commons.collections.CollectionUtils;
@ -351,21 +352,28 @@ public class TestPlanService {
}
testPlan.setTotal(testPlan.getTotal() + functionalExecTotal);
calcExecResultStatus(testPlan.getId(), testPlan, planTestPlanApiCaseService::getExecResultByPlanId);
Set<String> serviceIdSet = DiscoveryUtil.getServiceIdSet();
calcExecResultStatus(testPlan.getId(), testPlan, planTestPlanScenarioCaseService::getExecResultByPlanId);
if (serviceIdSet.contains(MicroServiceName.API_TEST)) {
calcExecResultStatus(testPlan.getId(), testPlan, planTestPlanApiCaseService::getExecResultByPlanId);
calcExecResultStatus(testPlan.getId(), testPlan, planTestPlanScenarioCaseService::getExecResultByPlanId);
}
calcExecResultStatus(testPlan.getId(), testPlan, planTestPlanLoadCaseService::getExecResultByPlanId);
if (serviceIdSet.contains(MicroServiceName.PERFORMANCE_TEST)) {
calcExecResultStatus(testPlan.getId(), testPlan, planTestPlanLoadCaseService::getExecResultByPlanId);
}
List<String> uiScenarioExecResults = calcExecResultStatus(testPlan.getId(), testPlan, planTestPlanUiScenarioCaseService::getExecResultByPlanId);
uiScenarioExecResults.forEach(item -> {
if (StringUtils.isNotBlank(item)) {
testPlan.setTested(testPlan.getTested() + 1);
if (StringUtils.equals(item, "Success")) {
testPlan.setPassed(testPlan.getPassed() + 1);
if (serviceIdSet.contains(MicroServiceName.UI_TEST)) {
List<String> uiScenarioExecResults = calcExecResultStatus(testPlan.getId(), testPlan, planTestPlanUiScenarioCaseService::getExecResultByPlanId);
uiScenarioExecResults.forEach(item -> {
if (StringUtils.isNotBlank(item)) {
testPlan.setTested(testPlan.getTested() + 1);
if (StringUtils.equals(item, "Success")) {
testPlan.setPassed(testPlan.getPassed() + 1);
}
}
}
});
});
}
testPlan.setPassRate(MathUtils.getPercentWithDecimal(testPlan.getTested() == 0 ? 0 : testPlan.getPassed() * 1.0 / testPlan.getTotal()));
testPlan.setTestRate(MathUtils.getPercentWithDecimal(testPlan.getTotal() == 0 ? 0 : testPlan.getTested() * 1.0 / testPlan.getTotal()));
@ -445,8 +453,20 @@ public class TestPlanService {
statusList.addAll(extTestPlanTestCaseMapper.getExecResultByPlanId(testPlanId));
try {
statusList.addAll(planTestPlanApiCaseService.getExecResultByPlanId(testPlanId));
} catch (MSException e) {
LogUtil.error(e);
}
try {
statusList.addAll(planTestPlanScenarioCaseService.getExecResultByPlanId(testPlanId));
} catch (MSException e) {
LogUtil.error(e);
}
try {
statusList.addAll(planTestPlanLoadCaseService.getExecResultByPlanId(testPlanId));
} catch (MSException e) {
LogUtil.error(e);
}
try {
statusList.addAll(planTestPlanUiScenarioCaseService.getExecResultByPlanId(testPlanId));
} catch (MSException e) {
LogUtil.error(e);
@ -761,8 +781,7 @@ public class TestPlanService {
@Transactional(propagation = Propagation.NOT_SUPPORTED)
TestPlanScheduleReportInfoDTO genTestPlanReport(String planReportId, String planId, String userId, String triggerMode, RunModeConfigDTO runModeConfigDTO) {
TestPlanScheduleReportInfoDTO reportInfoDTO = testPlanReportService.genTestPlanReportBySchedule(planReportId, planId, userId, triggerMode, runModeConfigDTO);
return reportInfoDTO;
return testPlanReportService.genTestPlanReportBySchedule(planReportId, planId, userId, triggerMode, runModeConfigDTO);
}
public String run(String testPlanID, String projectID, String userId, String triggerMode, String planReportId, String apiRunConfig) {
@ -1805,6 +1824,9 @@ public class TestPlanService {
}
public boolean haveUiCase(String planId) {
if (!DiscoveryUtil.hasService(MicroServiceName.UI_TEST)) {
return false;
}
return planTestPlanUiScenarioCaseService.haveUiCase(planId);
}

View File

@ -1,16 +1,19 @@
package io.metersphere.plan.service.remote.gateway;
import io.metersphere.commons.constants.MicroServiceName;
import io.metersphere.dto.ServiceDTO;
import io.metersphere.service.RemoteService;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class GatewayService extends RemoteService {
public GatewayService() {
super(MicroServiceName.GATEWAY);
}
public Object getMicroServices() {
return microService.getForData(serviceName, "/services");
public List<ServiceDTO> getMicroServices() {
return microService.getForDataArray(serviceName, "/services", ServiceDTO.class);
}
}

View File

@ -94,17 +94,14 @@ public class PlanTestPlanLoadCaseService extends LoadTestService {
}
}
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public void relevanceByTestIds(List<String> performanceIds, String planId) {
microService.postForData(serviceName, BASE_UEL + "/relevance/" + planId, performanceIds);
}
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public List<String> getExecResultByPlanId(String planId) {
return (List<String>) microService.getForData(serviceName, BASE_UEL + "/plan/exec/result/" + planId);
}
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public List<PlanReportCaseDTO> selectStatusForPlanReport(String planId) {
return microService.getForDataArray(serviceName, BASE_UEL + "/get/report/status/" + planId, PlanReportCaseDTO.class);
}

View File

@ -1,6 +1,7 @@
package io.metersphere.plan.service.remote.ui;
import io.metersphere.base.domain.TestPlanUiScenario;
import io.metersphere.commons.constants.MicroServiceName;
import io.metersphere.commons.exception.MSException;
import io.metersphere.commons.utils.LogUtil;
import io.metersphere.dto.*;
@ -13,6 +14,7 @@ import io.metersphere.plan.request.api.ApiPlanReportRequest;
import io.metersphere.plan.service.remote.api.PlanTestPlanScenarioCaseService;
import io.metersphere.plan.service.remote.api.PlanUiScenarioReportService;
import io.metersphere.plan.utils.TestPlanStatusCalculator;
import io.metersphere.utils.DiscoveryUtil;
import org.jetbrains.annotations.NotNull;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
@ -32,7 +34,6 @@ public class PlanTestPlanUiScenarioCaseService extends UiTestService {
@Resource
private PlanUiScenarioReportService planUiScenarioReportService;
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public List<String> getExecResultByPlanId(String planId) {
return (List<String>) microService.getForData(serviceName, BASE_UEL + "/plan/exec/result/" + planId);
}

View File

@ -0,0 +1,23 @@
package io.metersphere.utils;
import io.metersphere.commons.utils.CommonBeanFactory;
import io.metersphere.dto.ServiceDTO;
import io.metersphere.plan.service.remote.gateway.GatewayService;
import java.util.Set;
import java.util.stream.Collectors;
public class DiscoveryUtil {
public static boolean hasService(String serviceId) {
return getServiceIdSet().contains(serviceId);
}
public static Set<String> getServiceIdSet() {
GatewayService gatewayService = CommonBeanFactory.getBean(GatewayService.class);
return gatewayService.getMicroServices()
.stream()
.map(ServiceDTO::getServiceId)
.collect(Collectors.toSet());
}
}

View File

@ -364,7 +364,7 @@ import HeaderLabelOperate from "metersphere-frontend/src/components/head/HeaderL
import MsTag from "metersphere-frontend/src/components/MsTag";
import MsTestPlanScheduleMaintain from "@/business/plan/components/ScheduleMaintain";
import {getCurrentProjectID, getCurrentUser, getCurrentUserId} from "metersphere-frontend/src/utils/token";
import {hasPermission} from "metersphere-frontend/src/utils/permission";
import {hasLicense, hasPermission} from "metersphere-frontend/src/utils/permission";
import {operationConfirm} from "metersphere-frontend/src/utils";
import PlanRunModeWithEnv from "@/business/plan/common/PlanRunModeWithEnv";
import MsTaskCenter from "metersphere-frontend/src/components/task/TaskCenter";
@ -878,13 +878,17 @@ export default {
},
haveUIScenario() {
return new Promise((resolve) => {
testPlanHaveUiCase(this.currentPlanId)
.then((r) => {
this.haveUICase = r.data;
resolve()
});
});
if (hasLicense()) {
return new Promise((resolve) => {
testPlanHaveUiCase(this.currentPlanId)
.then((r) => {
this.haveUICase = r.data;
resolve()
});
});
} else {
return new Promise(resolve => resolve());
}
}
}
};