fix(测试计划定时任务): 修复任务中心看不到定时任务执行的案例信息问题

修复任务中心看不到定时任务执行的案例信息问题
This commit is contained in:
song-tianyang 2021-11-24 17:17:14 +08:00 committed by song-tianyang
parent c8eebede55
commit ce0d69b6ca
3 changed files with 19 additions and 14 deletions

View File

@ -19,4 +19,6 @@ public class BatchRunDefinitionRequest {
//测试计划报告ID 测试计划执行时使用
private String planReportId;
private String userId;
}

View File

@ -396,9 +396,14 @@ public class TestPlanApiCaseService {
if (request.getConfig() != null && StringUtils.isNotEmpty(request.getConfig().getResourcePoolId())) {
apiResult.setActuator(request.getConfig().getResourcePoolId());
}
if (SessionUtils.getUser() != null) {
apiResult.setUserId(SessionUtils.getUser().getId());
if(StringUtils.isEmpty(request.getUserId())){
if (SessionUtils.getUser() != null) {
apiResult.setUserId(SessionUtils.getUser().getId());
}
}else {
apiResult.setUserId(request.getUserId());
}
apiResult.setResourceId(key.getApiCaseId());
apiResult.setStartTime(System.currentTimeMillis());
apiResult.setType(ApiRunMode.API_PLAN.name());

View File

@ -1070,7 +1070,7 @@ public class TestPlanService {
}
@Transactional(propagation = Propagation.NOT_SUPPORTED)
TestPlanScheduleReportInfoDTO genTestPlanReport(String projectID, String planId, String userId, String triggerMode){
TestPlanScheduleReportInfoDTO genTestPlanReport(String projectID, String planId, String userId, String triggerMode) {
TestPlanScheduleReportInfoDTO reportInfoDTO = testPlanReportService.genTestPlanReportBySchedule(projectID, planId, userId, triggerMode);
return reportInfoDTO;
}
@ -1164,14 +1164,14 @@ public class TestPlanService {
} catch (Exception e) {
LogUtil.error(e);
}
performaneThreadIDMap.put(performanceRequest.getTestPlanLoadId(),reportId);
performaneThreadIDMap.put(performanceRequest.getTestPlanLoadId(), reportId);
if (StringUtils.isNotEmpty(reportId)) {
executePerformanceIdMap.put(caseID, TestPlanApiExecuteStatus.RUNNING.name());
} else {
executePerformanceIdMap.put(caseID, TestPlanApiExecuteStatus.PREPARE.name());
}
}
TestPlanReportExecuteCatch.updateTestPlanThreadInfo(planReportId,null,null,performaneThreadIDMap);
TestPlanReportExecuteCatch.updateTestPlanThreadInfo(planReportId, null, null, performaneThreadIDMap);
if (!performaneReportIDMap.isEmpty()) {
//性能测试时保存性能测试报告ID在结果返回时用于捕捉并进行
testPlanReportService.updatePerformanceInfo(testPlanReport, performaneReportIDMap, triggerMode);
@ -1188,7 +1188,7 @@ public class TestPlanService {
testPlanLog.info("ReportId[" + planReportId + "] start run. TestPlanID:[" + testPlanID + "]. Execute api :" + JSONObject.toJSONString(executeApiCaseIdMap) + "; Execute scenario:" + JSONObject.toJSONString(executeScenarioCaseIdMap) + "; Execute performance:" + JSONObject.toJSONString(executePerformanceIdMap));
TestPlanReportExecuteCatch.updateApiTestPlanExecuteInfo(planReportId, executeApiCaseIdMap, executeScenarioCaseIdMap, executePerformanceIdMap);
//执行接口案例任务
this.executeApiTestCase(triggerMode, planReportId, new ArrayList<>(planApiCaseMap.keySet()), runModeConfig);
this.executeApiTestCase(triggerMode, planReportId, userId, new ArrayList<>(planApiCaseMap.keySet()), runModeConfig);
//执行场景执行任务
this.executeScenarioCase(planReportId, testPlanID, projectID, runModeConfig, triggerMode, userId, planScenarioIdsMap);
this.listenTaskExecuteStatus(planReportId);
@ -1210,11 +1210,9 @@ public class TestPlanService {
});
}
private void executeApiTestCase(String triggerMode, String planReportId, List<String> planCaseIds, RunModeConfig runModeConfig) {
private void executeApiTestCase(String triggerMode, String planReportId, String userId, List<String> planCaseIds, RunModeConfig runModeConfig) {
executorService.submit(() -> {
BatchRunDefinitionRequest request = new BatchRunDefinitionRequest();
// List<String> planIdList = new ArrayList<>(1);
// planIdList.add(testPlanId);
if (StringUtils.equals(triggerMode, ReportTriggerMode.API.name())) {
request.setTriggerMode(ApiRunMode.JENKINS_API_PLAN.name());
} else if (StringUtils.equals(triggerMode, ReportTriggerMode.MANUAL.name())) {
@ -1222,10 +1220,10 @@ public class TestPlanService {
} else {
request.setTriggerMode(ApiRunMode.SCHEDULE_API_PLAN.name());
}
request.setPlanIds(planCaseIds);
request.setPlanReportId(planReportId);
request.setConfig(runModeConfig);
request.setUserId(userId);
testPlanApiCaseService.run(request);
});
}
@ -1485,7 +1483,7 @@ public class TestPlanService {
continue;
}
if ((StringUtils.equals(envType, EnvironmentType.JSON.name()) && StringUtils.isBlank(env))
|| StringUtils.equals(envType, EnvironmentType.GROUP.name()) && StringUtils.isBlank(envGroupId)) {
|| StringUtils.equals(envType, EnvironmentType.GROUP.name()) && StringUtils.isBlank(envGroupId)) {
continue;
}
Map<String, String> map = new HashMap<>();
@ -1729,7 +1727,7 @@ public class TestPlanService {
}
}
public void buildApiReport(TestPlanSimpleReportDTO report, JSONObject config, TestPlanExecuteInfo executeInfo,boolean isFinish) {
public void buildApiReport(TestPlanSimpleReportDTO report, JSONObject config, TestPlanExecuteInfo executeInfo, boolean isFinish) {
if (MapUtils.isEmpty(executeInfo.getApiCaseExecInfo()) && MapUtils.isEmpty(executeInfo.getApiScenarioCaseExecInfo())) {
return;
}
@ -1739,12 +1737,12 @@ public class TestPlanService {
if (checkReportConfig(config, "api", "all")) {
if (MapUtils.isNotEmpty(executeInfo.getApiCaseExecInfo())) {
// 接口
apiAllCases = testPlanApiCaseService.getByApiExecReportIds(executeInfo.getApiCaseExecuteThreadMap(),isFinish);
apiAllCases = testPlanApiCaseService.getByApiExecReportIds(executeInfo.getApiCaseExecuteThreadMap(), isFinish);
report.setApiAllCases(apiAllCases);
}
if (MapUtils.isNotEmpty(executeInfo.getApiScenarioCaseExecInfo())) {
//场景
scenarioAllCases = testPlanScenarioCaseService.getAllCases(executeInfo.getApiScenarioThreadMap(),isFinish);
scenarioAllCases = testPlanScenarioCaseService.getAllCases(executeInfo.getApiScenarioThreadMap(), isFinish);
report.setScenarioAllCases(scenarioAllCases);
}
}