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 测试计划执行时使用 //测试计划报告ID 测试计划执行时使用
private String planReportId; private String planReportId;
private String userId;
} }

View File

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

View File

@ -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)); 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); 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.executeScenarioCase(planReportId, testPlanID, projectID, runModeConfig, triggerMode, userId, planScenarioIdsMap);
this.listenTaskExecuteStatus(planReportId); 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(() -> { executorService.submit(() -> {
BatchRunDefinitionRequest request = new BatchRunDefinitionRequest(); BatchRunDefinitionRequest request = new BatchRunDefinitionRequest();
// List<String> planIdList = new ArrayList<>(1);
// planIdList.add(testPlanId);
if (StringUtils.equals(triggerMode, ReportTriggerMode.API.name())) { if (StringUtils.equals(triggerMode, ReportTriggerMode.API.name())) {
request.setTriggerMode(ApiRunMode.JENKINS_API_PLAN.name()); request.setTriggerMode(ApiRunMode.JENKINS_API_PLAN.name());
} else if (StringUtils.equals(triggerMode, ReportTriggerMode.MANUAL.name())) { } else if (StringUtils.equals(triggerMode, ReportTriggerMode.MANUAL.name())) {
@ -1222,10 +1220,10 @@ public class TestPlanService {
} else { } else {
request.setTriggerMode(ApiRunMode.SCHEDULE_API_PLAN.name()); request.setTriggerMode(ApiRunMode.SCHEDULE_API_PLAN.name());
} }
request.setPlanIds(planCaseIds); request.setPlanIds(planCaseIds);
request.setPlanReportId(planReportId); request.setPlanReportId(planReportId);
request.setConfig(runModeConfig); request.setConfig(runModeConfig);
request.setUserId(userId);
testPlanApiCaseService.run(request); testPlanApiCaseService.run(request);
}); });
} }