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

@ -1070,7 +1070,7 @@ public class TestPlanService {
} }
@Transactional(propagation = Propagation.NOT_SUPPORTED) @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); TestPlanScheduleReportInfoDTO reportInfoDTO = testPlanReportService.genTestPlanReportBySchedule(projectID, planId, userId, triggerMode);
return reportInfoDTO; return reportInfoDTO;
} }
@ -1164,14 +1164,14 @@ public class TestPlanService {
} catch (Exception e) { } catch (Exception e) {
LogUtil.error(e); LogUtil.error(e);
} }
performaneThreadIDMap.put(performanceRequest.getTestPlanLoadId(),reportId); performaneThreadIDMap.put(performanceRequest.getTestPlanLoadId(), reportId);
if (StringUtils.isNotEmpty(reportId)) { if (StringUtils.isNotEmpty(reportId)) {
executePerformanceIdMap.put(caseID, TestPlanApiExecuteStatus.RUNNING.name()); executePerformanceIdMap.put(caseID, TestPlanApiExecuteStatus.RUNNING.name());
} else { } else {
executePerformanceIdMap.put(caseID, TestPlanApiExecuteStatus.PREPARE.name()); executePerformanceIdMap.put(caseID, TestPlanApiExecuteStatus.PREPARE.name());
} }
} }
TestPlanReportExecuteCatch.updateTestPlanThreadInfo(planReportId,null,null,performaneThreadIDMap); TestPlanReportExecuteCatch.updateTestPlanThreadInfo(planReportId, null, null, performaneThreadIDMap);
if (!performaneReportIDMap.isEmpty()) { if (!performaneReportIDMap.isEmpty()) {
//性能测试时保存性能测试报告ID在结果返回时用于捕捉并进行 //性能测试时保存性能测试报告ID在结果返回时用于捕捉并进行
testPlanReportService.updatePerformanceInfo(testPlanReport, performaneReportIDMap, triggerMode); 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)); 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);
}); });
} }
@ -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())) { if (MapUtils.isEmpty(executeInfo.getApiCaseExecInfo()) && MapUtils.isEmpty(executeInfo.getApiScenarioCaseExecInfo())) {
return; return;
} }
@ -1739,12 +1737,12 @@ public class TestPlanService {
if (checkReportConfig(config, "api", "all")) { if (checkReportConfig(config, "api", "all")) {
if (MapUtils.isNotEmpty(executeInfo.getApiCaseExecInfo())) { if (MapUtils.isNotEmpty(executeInfo.getApiCaseExecInfo())) {
// 接口 // 接口
apiAllCases = testPlanApiCaseService.getByApiExecReportIds(executeInfo.getApiCaseExecuteThreadMap(),isFinish); apiAllCases = testPlanApiCaseService.getByApiExecReportIds(executeInfo.getApiCaseExecuteThreadMap(), isFinish);
report.setApiAllCases(apiAllCases); report.setApiAllCases(apiAllCases);
} }
if (MapUtils.isNotEmpty(executeInfo.getApiScenarioCaseExecInfo())) { if (MapUtils.isNotEmpty(executeInfo.getApiScenarioCaseExecInfo())) {
//场景 //场景
scenarioAllCases = testPlanScenarioCaseService.getAllCases(executeInfo.getApiScenarioThreadMap(),isFinish); scenarioAllCases = testPlanScenarioCaseService.getAllCases(executeInfo.getApiScenarioThreadMap(), isFinish);
report.setScenarioAllCases(scenarioAllCases); report.setScenarioAllCases(scenarioAllCases);
} }
} }