mirror of
https://gitee.com/fit2cloud-feizhiyun/MeterSphere.git
synced 2024-12-04 21:19:52 +08:00
fix(测试计划): 测试计划执行过程优化
测试计划执行过程优化
This commit is contained in:
parent
61012b854d
commit
9f18193c95
@ -46,7 +46,5 @@ public class RunScenarioRequest {
|
|||||||
//生成测试报告:当isTestPlanScheduleJob为ture时使用
|
//生成测试报告:当isTestPlanScheduleJob为ture时使用
|
||||||
private String testPlanReportId;
|
private String testPlanReportId;
|
||||||
|
|
||||||
private String testPlanReportContentId;
|
|
||||||
|
|
||||||
private String requestOriginator;
|
private String requestOriginator;
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,5 @@ public class SchedulePlanScenarioExecuteRequest {
|
|||||||
|
|
||||||
private String testPlanReportId;
|
private String testPlanReportId;
|
||||||
|
|
||||||
private String planReportContentId;
|
|
||||||
|
|
||||||
private RunModeConfigDTO config;
|
private RunModeConfigDTO config;
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,4 @@ public class BatchRunDefinitionRequest {
|
|||||||
//测试计划报告ID。 测试计划执行时使用
|
//测试计划报告ID。 测试计划执行时使用
|
||||||
private String planReportId;
|
private String planReportId;
|
||||||
|
|
||||||
private String planReportContentId;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -89,12 +89,10 @@ public class ApiCaseExecuteService {
|
|||||||
|
|
||||||
List<MsExecResponseDTO> responseDTOS = new LinkedList<>();
|
List<MsExecResponseDTO> responseDTOS = new LinkedList<>();
|
||||||
Map<String, ApiDefinitionExecResult> executeQueue = new HashMap<>();
|
Map<String, ApiDefinitionExecResult> executeQueue = new HashMap<>();
|
||||||
Map<String, String> testPlanCaseIdAndReportIdMap = new HashMap<>();
|
|
||||||
String status = request.getConfig().getMode().equals(RunModeConstants.SERIAL.toString()) ? APITestStatus.Waiting.name() : APITestStatus.Running.name();
|
String status = request.getConfig().getMode().equals(RunModeConstants.SERIAL.toString()) ? APITestStatus.Waiting.name() : APITestStatus.Running.name();
|
||||||
planApiCases.forEach(testPlanApiCase -> {
|
planApiCases.forEach(testPlanApiCase -> {
|
||||||
ApiDefinitionExecResult report = ApiDefinitionExecResultUtil.addResult(request, testPlanApiCase, status, batchMapper);
|
ApiDefinitionExecResult report = ApiDefinitionExecResultUtil.addResult(request, testPlanApiCase, status, batchMapper);
|
||||||
executeQueue.put(testPlanApiCase.getId(), report);
|
executeQueue.put(testPlanApiCase.getId(), report);
|
||||||
testPlanCaseIdAndReportIdMap.put(testPlanApiCase.getId(), report.getId());
|
|
||||||
responseDTOS.add(new MsExecResponseDTO(testPlanApiCase.getId(), report.getId(), request.getTriggerMode()));
|
responseDTOS.add(new MsExecResponseDTO(testPlanApiCase.getId(), report.getId(), request.getTriggerMode()));
|
||||||
});
|
});
|
||||||
sqlSession.flushStatements();
|
sqlSession.flushStatements();
|
||||||
@ -108,11 +106,6 @@ public class ApiCaseExecuteService {
|
|||||||
String runMode = StringUtils.equals(request.getTriggerMode(), TriggerMode.MANUAL.name()) ? ApiRunMode.API_PLAN.name() : ApiRunMode.SCHEDULE_API_PLAN.name();
|
String runMode = StringUtils.equals(request.getTriggerMode(), TriggerMode.MANUAL.name()) ? ApiRunMode.API_PLAN.name() : ApiRunMode.SCHEDULE_API_PLAN.name();
|
||||||
DBTestQueue deQueue = apiExecutionQueueService.add(executeQueue, poolId, ApiRunMode.API_PLAN.name(), request.getPlanReportId(), reportType, runMode, request.getConfig().getEnvMap());
|
DBTestQueue deQueue = apiExecutionQueueService.add(executeQueue, poolId, ApiRunMode.API_PLAN.name(), request.getPlanReportId(), reportType, runMode, request.getConfig().getEnvMap());
|
||||||
|
|
||||||
//如果是测试计划生成报告的执行,则更新执行信息、执行线程信息。
|
|
||||||
if (StringUtils.isNotEmpty(request.getPlanReportContentId())) {
|
|
||||||
TestPlanReportService testPlanReportService = CommonBeanFactory.getBean(TestPlanReportService.class);
|
|
||||||
testPlanReportService.updateTestPlanReportContentReportIds(request.getPlanReportContentId(),testPlanCaseIdAndReportIdMap,null,null);
|
|
||||||
}
|
|
||||||
// 开始选择执行模式
|
// 开始选择执行模式
|
||||||
if (request.getConfig() != null && request.getConfig().getMode().equals(RunModeConstants.SERIAL.toString())) {
|
if (request.getConfig() != null && request.getConfig().getMode().equals(RunModeConstants.SERIAL.toString())) {
|
||||||
LoggerUtil.debug("开始串行执行");
|
LoggerUtil.debug("开始串行执行");
|
||||||
|
@ -224,7 +224,6 @@ public class ApiScenarioExecuteService {
|
|||||||
}
|
}
|
||||||
String projectId = request.getProjectId();
|
String projectId = request.getProjectId();
|
||||||
Map<String, ApiScenarioWithBLOBs> scenarioMap = apiScenarios.stream().collect(Collectors.toMap(ApiScenarioWithBLOBs::getId, Function.identity(), (t1, t2) -> t1));
|
Map<String, ApiScenarioWithBLOBs> scenarioMap = apiScenarios.stream().collect(Collectors.toMap(ApiScenarioWithBLOBs::getId, Function.identity(), (t1, t2) -> t1));
|
||||||
Map<String, String> scenarioReportIdMap = new HashMap<>();
|
|
||||||
for (Map.Entry<String, String> entry : planScenarioIdMap.entrySet()) {
|
for (Map.Entry<String, String> entry : planScenarioIdMap.entrySet()) {
|
||||||
String testPlanScenarioId = entry.getKey();
|
String testPlanScenarioId = entry.getKey();
|
||||||
String scenarioId = entry.getValue();
|
String scenarioId = entry.getValue();
|
||||||
@ -256,9 +255,6 @@ public class ApiScenarioExecuteService {
|
|||||||
report = apiScenarioReportService.init(reportId, testPlanScenarioId, scenario.getName(), request.getTriggerMode(),
|
report = apiScenarioReportService.init(reportId, testPlanScenarioId, scenario.getName(), request.getTriggerMode(),
|
||||||
request.getExecuteType(), projectId, request.getReportUserID(), request.getConfig(), scenario.getId());
|
request.getExecuteType(), projectId, request.getReportUserID(), request.getConfig(), scenario.getId());
|
||||||
|
|
||||||
if (report != null && StringUtils.isNotEmpty(request.getTestPlanReportContentId())) {
|
|
||||||
scenarioReportIdMap.put(testPlanScenarioId, report.getId());
|
|
||||||
}
|
|
||||||
scenarioIds.add(scenario.getId());
|
scenarioIds.add(scenario.getId());
|
||||||
if (request.getConfig() != null && StringUtils.isNotBlank(request.getConfig().getResourcePoolId())) {
|
if (request.getConfig() != null && StringUtils.isNotBlank(request.getConfig().getResourcePoolId())) {
|
||||||
RunModeDataDTO runModeDataDTO = new RunModeDataDTO();
|
RunModeDataDTO runModeDataDTO = new RunModeDataDTO();
|
||||||
@ -294,10 +290,6 @@ public class ApiScenarioExecuteService {
|
|||||||
// 重置报告ID
|
// 重置报告ID
|
||||||
reportId = UUID.randomUUID().toString();
|
reportId = UUID.randomUUID().toString();
|
||||||
}
|
}
|
||||||
if(StringUtils.isNotEmpty(request.getTestPlanReportContentId())){
|
|
||||||
TestPlanReportService testPlanReportService = CommonBeanFactory.getBean(TestPlanReportService.class);
|
|
||||||
testPlanReportService.updateTestPlanReportContentReportIds(request.getTestPlanReportContentId(),null,scenarioReportIdMap,null);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -16,7 +16,6 @@ import java.util.Map;
|
|||||||
@Setter
|
@Setter
|
||||||
public class TestPlanScheduleReportInfoDTO {
|
public class TestPlanScheduleReportInfoDTO {
|
||||||
private TestPlanReport testPlanReport;
|
private TestPlanReport testPlanReport;
|
||||||
private TestPlanReportContent testPlanReportContent;
|
|
||||||
private Map<String, String> planScenarioIdMap = new LinkedHashMap<>();
|
private Map<String, String> planScenarioIdMap = new LinkedHashMap<>();
|
||||||
private Map<String, String> apiTestCaseDataMap = new LinkedHashMap<>();
|
private Map<String, String> apiTestCaseDataMap = new LinkedHashMap<>();
|
||||||
private Map<String, String> performanceIdMap = new LinkedHashMap<>();
|
private Map<String, String> performanceIdMap = new LinkedHashMap<>();
|
||||||
|
@ -184,16 +184,6 @@ public class TestPlanReportService {
|
|||||||
testPlanReport.setEndTime(System.currentTimeMillis());
|
testPlanReport.setEndTime(System.currentTimeMillis());
|
||||||
testPlanReport.setIsNew(true);
|
testPlanReport.setIsNew(true);
|
||||||
|
|
||||||
TestPlanReportContentWithBLOBs testPlanReportContent = new TestPlanReportContentWithBLOBs();
|
|
||||||
testPlanReportContent.setId(UUID.randomUUID().toString());
|
|
||||||
testPlanReportContent.setTestPlanReportId(testPlanReportID);
|
|
||||||
if (testPlanReportContent.getStartTime() == null) {
|
|
||||||
testPlanReportContent.setStartTime(System.currentTimeMillis());
|
|
||||||
}
|
|
||||||
if (testPlanReportContent.getEndTime() == null) {
|
|
||||||
testPlanReportContent.setEndTime(System.currentTimeMillis());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (saveRequest.isCountResources()) {
|
if (saveRequest.isCountResources()) {
|
||||||
List<TestPlanApiCase> testPlanApiCaseList = extTestPlanApiCaseMapper.selectLegalDataByTestPlanId(saveRequest.getPlanId());
|
List<TestPlanApiCase> testPlanApiCaseList = extTestPlanApiCaseMapper.selectLegalDataByTestPlanId(saveRequest.getPlanId());
|
||||||
List<String> apiCaseIdList = testPlanApiCaseList.stream().map(TestPlanApiCase::getApiCaseId).collect(Collectors.toList());
|
List<String> apiCaseIdList = testPlanApiCaseList.stream().map(TestPlanApiCase::getApiCaseId).collect(Collectors.toList());
|
||||||
@ -222,7 +212,6 @@ public class TestPlanReportService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
testPlanReportMapper.insert(testPlanReport);
|
testPlanReportMapper.insert(testPlanReport);
|
||||||
testPlanReportContentMapper.insert(testPlanReportContent);
|
|
||||||
|
|
||||||
//更新TestPlan状态,改为进行中
|
//更新TestPlan状态,改为进行中
|
||||||
testPlan.setStatus(TestPlanStatus.Underway.name());
|
testPlan.setStatus(TestPlanStatus.Underway.name());
|
||||||
@ -230,7 +219,6 @@ public class TestPlanReportService {
|
|||||||
|
|
||||||
TestPlanScheduleReportInfoDTO returnDTO = new TestPlanScheduleReportInfoDTO();
|
TestPlanScheduleReportInfoDTO returnDTO = new TestPlanScheduleReportInfoDTO();
|
||||||
returnDTO.setTestPlanReport(testPlanReport);
|
returnDTO.setTestPlanReport(testPlanReport);
|
||||||
returnDTO.setTestPlanReportContent(testPlanReportContent);
|
|
||||||
return returnDTO;
|
return returnDTO;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -337,6 +325,16 @@ public class TestPlanReportService {
|
|||||||
testPlanReport.setUpdateTime(endTime);
|
testPlanReport.setUpdateTime(endTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//更新content表对结束日期
|
||||||
|
TestPlanReportContentExample contentExample = new TestPlanReportContentExample();
|
||||||
|
contentExample.createCriteria().andTestPlanReportIdEqualTo(testPlanReportId);
|
||||||
|
|
||||||
|
TestPlanReportContentWithBLOBs content = new TestPlanReportContentWithBLOBs();
|
||||||
|
content.setStartTime(testPlanReport.getStartTime());
|
||||||
|
content.setEndTime(endTime);
|
||||||
|
testPlanReportContentMapper.updateByExampleSelective(content,contentExample);
|
||||||
|
|
||||||
|
|
||||||
//更新测试计划并发送通知
|
//更新测试计划并发送通知
|
||||||
testPlanReport.setIsApiCaseExecuting(false);
|
testPlanReport.setIsApiCaseExecuting(false);
|
||||||
testPlanReport.setIsScenarioExecuting(false);
|
testPlanReport.setIsScenarioExecuting(false);
|
||||||
@ -732,10 +730,14 @@ public class TestPlanReportService {
|
|||||||
return testPlanReportContent;
|
return testPlanReportContent;
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void updateTestPlanReportContentReportIds(String testPlanReportContentId, Map<String, String> apiCaseReportMap, Map<String, String> scenarioReportIdMap, Map<String, String> loadCaseReportIdMap) {
|
public void createTestPlanReportContentReportIds(String testPlanReportID, Map<String, String> apiCaseReportMap, Map<String, String> scenarioReportIdMap, Map<String, String> loadCaseReportIdMap) {
|
||||||
if (StringUtils.isNotEmpty(testPlanReportContentId)) {
|
TestPlanReportContentExample example = new TestPlanReportContentExample();
|
||||||
|
example.createCriteria().andTestPlanReportIdEqualTo(testPlanReportID);
|
||||||
|
long dataCount = testPlanReportContentMapper.countByExample(example);
|
||||||
|
if(dataCount == 0){
|
||||||
TestPlanReportContentWithBLOBs content = new TestPlanReportContentWithBLOBs();
|
TestPlanReportContentWithBLOBs content = new TestPlanReportContentWithBLOBs();
|
||||||
content.setId(testPlanReportContentId);
|
content.setId(UUID.randomUUID().toString());
|
||||||
|
content.setTestPlanReportId(testPlanReportID);
|
||||||
|
|
||||||
if (MapUtils.isNotEmpty(apiCaseReportMap)) {
|
if (MapUtils.isNotEmpty(apiCaseReportMap)) {
|
||||||
content.setPlanApiCaseReportStruct(JSONObject.toJSONString(apiCaseReportMap));
|
content.setPlanApiCaseReportStruct(JSONObject.toJSONString(apiCaseReportMap));
|
||||||
@ -746,10 +748,7 @@ public class TestPlanReportService {
|
|||||||
if (MapUtils.isNotEmpty(loadCaseReportIdMap)) {
|
if (MapUtils.isNotEmpty(loadCaseReportIdMap)) {
|
||||||
content.setPlanLoadCaseReportStruct(JSONObject.toJSONString(loadCaseReportIdMap));
|
content.setPlanLoadCaseReportStruct(JSONObject.toJSONString(loadCaseReportIdMap));
|
||||||
}
|
}
|
||||||
|
testPlanReportContentMapper.insert(content);
|
||||||
if (StringUtils.isNotEmpty(content.getPlanApiCaseReportStruct()) || StringUtils.isNotEmpty(content.getPlanScenarioReportStruct()) || StringUtils.isNotEmpty(content.getPlanLoadCaseReportStruct())) {
|
|
||||||
testPlanReportContentMapper.updateByPrimaryKeySelective(content);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -960,7 +960,6 @@ public class TestPlanService {
|
|||||||
request.setConfig(planScenarioExecuteRequest.getConfig());
|
request.setConfig(planScenarioExecuteRequest.getConfig());
|
||||||
request.setTestPlanScheduleJob(true);
|
request.setTestPlanScheduleJob(true);
|
||||||
request.setTestPlanReportId(planScenarioExecuteRequest.getTestPlanReportId());
|
request.setTestPlanReportId(planScenarioExecuteRequest.getTestPlanReportId());
|
||||||
request.setTestPlanReportContentId(planScenarioExecuteRequest.getPlanReportContentId());
|
|
||||||
request.setId(UUID.randomUUID().toString());
|
request.setId(UUID.randomUUID().toString());
|
||||||
request.setProjectId(planScenarioExecuteRequest.getProjectId());
|
request.setProjectId(planScenarioExecuteRequest.getProjectId());
|
||||||
request.setRequestOriginator("TEST_PLAN");
|
request.setRequestOriginator("TEST_PLAN");
|
||||||
@ -1070,26 +1069,27 @@ public class TestPlanService {
|
|||||||
|
|
||||||
|
|
||||||
//执行接口案例任务
|
//执行接口案例任务
|
||||||
this.executeApiTestCase(triggerMode, planReportId, reportInfoDTO.getTestPlanReportContent().getId(), userId, new ArrayList<>(reportInfoDTO.getApiTestCaseDataMap().keySet()), runModeConfig);
|
Map<String,String> apiCaseReportMap = this.executeApiTestCase(triggerMode, planReportId,userId, new ArrayList<>(reportInfoDTO.getApiTestCaseDataMap().keySet()), runModeConfig);
|
||||||
//执行场景执行任务
|
//执行场景执行任务
|
||||||
this.executeScenarioCase(planReportId, reportInfoDTO.getTestPlanReportContent().getId(), testPlanID, projectID, runModeConfig, triggerMode, userId, reportInfoDTO.getPlanScenarioIdMap());
|
Map<String,String> scenarioReportMap = this.executeScenarioCase(planReportId, testPlanID, projectID, runModeConfig, triggerMode, userId, reportInfoDTO.getPlanScenarioIdMap());
|
||||||
//执行性能测试任务
|
//执行性能测试任务
|
||||||
this.executeLoadCaseTask(runModeConfig, triggerMode, reportInfoDTO.getPerformanceIdMap(), reportInfoDTO.getTestPlanReportContent().getId());
|
Map<String,String> loadCaseReportMap = this.executeLoadCaseTask(runModeConfig, triggerMode, reportInfoDTO.getPerformanceIdMap());
|
||||||
|
testPlanReportService.createTestPlanReportContentReportIds(planReportId, apiCaseReportMap,scenarioReportMap,loadCaseReportMap);
|
||||||
return planReportId;
|
return planReportId;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void executeApiTestCase(String triggerMode, String planReportId, String reportContentId, String userId, List<String> planCaseIds, RunModeConfigDTO runModeConfig) {
|
private Map<String,String> executeApiTestCase(String triggerMode, String planReportId, String userId, List<String> planCaseIds, RunModeConfigDTO runModeConfig) {
|
||||||
BatchRunDefinitionRequest request = new BatchRunDefinitionRequest();
|
BatchRunDefinitionRequest request = new BatchRunDefinitionRequest();
|
||||||
request.setTriggerMode(triggerMode);
|
request.setTriggerMode(triggerMode);
|
||||||
request.setPlanIds(planCaseIds);
|
request.setPlanIds(planCaseIds);
|
||||||
request.setPlanReportId(planReportId);
|
request.setPlanReportId(planReportId);
|
||||||
request.setConfig(runModeConfig);
|
request.setConfig(runModeConfig);
|
||||||
request.setUserId(userId);
|
request.setUserId(userId);
|
||||||
request.setPlanReportContentId(reportContentId);
|
List<MsExecResponseDTO> dtoList = testPlanApiCaseService.run(request);
|
||||||
testPlanApiCaseService.run(request);
|
return this.parseMsExecREsponseDTOToTestIdReportMap(dtoList);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void executeScenarioCase(String planReportId, String reportContentId, String testPlanID, String projectID, RunModeConfigDTO runModeConfig, String triggerMode, String userId, Map<String, String> planScenarioIdMap) {
|
private Map<String,String> executeScenarioCase(String planReportId, String testPlanID, String projectID, RunModeConfigDTO runModeConfig, String triggerMode, String userId, Map<String, String> planScenarioIdMap) {
|
||||||
if (!planScenarioIdMap.isEmpty()) {
|
if (!planScenarioIdMap.isEmpty()) {
|
||||||
SchedulePlanScenarioExecuteRequest scenarioRequest = new SchedulePlanScenarioExecuteRequest();
|
SchedulePlanScenarioExecuteRequest scenarioRequest = new SchedulePlanScenarioExecuteRequest();
|
||||||
String senarionReportID = UUID.randomUUID().toString();
|
String senarionReportID = UUID.randomUUID().toString();
|
||||||
@ -1113,15 +1113,28 @@ public class TestPlanService {
|
|||||||
scenarioRequest.setReportUserID(userId);
|
scenarioRequest.setReportUserID(userId);
|
||||||
scenarioRequest.setTestPlanID(testPlanID);
|
scenarioRequest.setTestPlanID(testPlanID);
|
||||||
scenarioRequest.setTestPlanReportId(planReportId);
|
scenarioRequest.setTestPlanReportId(planReportId);
|
||||||
scenarioRequest.setPlanReportContentId(reportContentId);
|
|
||||||
scenarioRequest.setConfig(runModeConfig);
|
scenarioRequest.setConfig(runModeConfig);
|
||||||
this.scenarioRunModeConfig(scenarioRequest);
|
List<MsExecResponseDTO> dtoList = this.scenarioRunModeConfig(scenarioRequest);
|
||||||
|
return this.parseMsExecREsponseDTOToTestIdReportMap(dtoList);
|
||||||
|
}else {
|
||||||
|
return new HashMap<>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void executeLoadCaseTask(RunModeConfigDTO runModeConfig, String triggerMode, Map<String, String> performanceIdMap, String reportContentId) {
|
private Map<String, String> parseMsExecREsponseDTOToTestIdReportMap(List<MsExecResponseDTO> dtoList) {
|
||||||
|
Map<String,String> returnMap = new HashMap<>();
|
||||||
|
if(CollectionUtils.isNotEmpty(dtoList)){
|
||||||
|
dtoList.forEach( item -> {
|
||||||
|
if(StringUtils.isNotEmpty(item.getTestId()) && StringUtils.isNotEmpty(item.getReportId())){
|
||||||
|
returnMap.put(item.getTestId(),item.getReportId());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return returnMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<String, String> executeLoadCaseTask(RunModeConfigDTO runModeConfig, String triggerMode, Map<String, String> performanceIdMap) {
|
||||||
Map<String, String> loadCaseReportMap = new HashMap<>();
|
Map<String, String> loadCaseReportMap = new HashMap<>();
|
||||||
|
|
||||||
for (Map.Entry<String, String> entry : performanceIdMap.entrySet()) {
|
for (Map.Entry<String, String> entry : performanceIdMap.entrySet()) {
|
||||||
String id = entry.getKey();
|
String id = entry.getKey();
|
||||||
String caseID = entry.getValue();
|
String caseID = entry.getValue();
|
||||||
@ -1160,7 +1173,7 @@ public class TestPlanService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
testPlanReportService.updateTestPlanReportContentReportIds(reportContentId, null, null, loadCaseReportMap);
|
return loadCaseReportMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getLogDetails(String id) {
|
public String getLogDetails(String id) {
|
||||||
|
Loading…
Reference in New Issue
Block a user