diff --git a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionExecResultService.java b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionExecResultService.java index baa26b779e..49cc3e7613 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionExecResultService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionExecResultService.java @@ -135,10 +135,9 @@ public class ApiDefinitionExecResultService { */ public void saveApiResultByScheduleTask(TestResult result, String type) { String saveResultType = type; - if (StringUtils.equalsAny(ApiRunMode.SCHEDULE_API_PLAN.name(), saveResultType)) { + if (StringUtils.equalsAny(saveResultType, ApiRunMode.SCHEDULE_API_PLAN.name(), ApiRunMode.JENKINS_API_PLAN.name())) { saveResultType = ApiRunMode.API_PLAN.name(); } - String finalSaveResultType = saveResultType; result.getScenarios().get(0).getRequestResults().forEach(item -> { ApiDefinitionExecResult saveResult = new ApiDefinitionExecResult(); @@ -154,7 +153,12 @@ public class ApiDefinitionExecResultService { saveResult.setName(caseWithBLOBs.getName()); } } - saveResult.setTriggerMode(TriggerMode.SCHEDULE.name()); + if (StringUtils.equals(type, ApiRunMode.JENKINS_API_PLAN.name())) { + saveResult.setTriggerMode(TriggerMode.API.name()); + } else { + saveResult.setTriggerMode(TriggerMode.SCHEDULE.name()); + } + saveResult.setResourceId(item.getName()); saveResult.setActuator("LOCAL"); saveResult.setContent(JSON.toJSONString(item)); @@ -172,12 +176,17 @@ public class ApiDefinitionExecResultService { apiCase.setStatus(status); apiCase.setUpdateTime(System.currentTimeMillis()); testPlanApiCaseService.updateByPrimaryKeySelective(apiCase); + } else if (StringUtils.equals(type, ApiRunMode.JENKINS_SCENARIO_PLAN.name())) { + TestPlanApiCase apiCase = testPlanApiCaseService.getById(item.getName()); + userID = Objects.requireNonNull(SessionUtils.getUser()).getId(); + apiCase.setStatus(status); + apiCase.setUpdateTime(System.currentTimeMillis()); + testPlanApiCaseService.updateByPrimaryKeySelective(apiCase); } else { userID = Objects.requireNonNull(SessionUtils.getUser()).getId(); testPlanApiCaseService.setExecResult(item.getName(), status, item.getStartTime()); testCaseReviewApiCaseService.setExecResult(item.getName(), status, item.getStartTime()); } - saveResult.setUserId(userID); // 前一条数据内容清空 ApiDefinitionExecResult prevResult = extApiDefinitionExecResultMapper.selectMaxResultByResourceIdAndType(item.getName(), finalSaveResultType); diff --git a/backend/src/main/java/io/metersphere/api/service/TestResultService.java b/backend/src/main/java/io/metersphere/api/service/TestResultService.java index fbb4cfa623..e9b480d0a8 100644 --- a/backend/src/main/java/io/metersphere/api/service/TestResultService.java +++ b/backend/src/main/java/io/metersphere/api/service/TestResultService.java @@ -68,6 +68,7 @@ public class TestResultService { if (StringUtils.isBlank(debugReportId)) { apiDefinitionExecResultService.saveApiResult(testResult, ApiRunMode.DEFINITION.name(), TriggerMode.MANUAL.name()); } + //jenkins单接口执行 } else if (StringUtils.equals(runMode, ApiRunMode.JENKINS.name())) { apiDefinitionExecResultService.saveApiResult(testResult, ApiRunMode.DEFINITION.name(), TriggerMode.API.name()); ApiTestCaseWithBLOBs apiTestCaseWithBLOBs = apiTestCaseService.getInfoJenkins(testResult.getTestId()); @@ -85,31 +86,8 @@ public class TestResultService { reportTask.setExecutor(userName); reportTask.setExecutionTime(DateUtils.getTimeString(apiTestCaseWithBLOBs.getCreateTime())); reportTask.setExecutionEnvironment(name); - } else if (StringUtils.equals(runMode, ApiRunMode.JENKINS_API_PLAN.name())) { - apiDefinitionExecResultService.saveApiResult(testResult, ApiRunMode.API_PLAN.name(), TriggerMode.API.name()); - ApiTestCaseWithBLOBs apiTestCaseWithBLOBs = apiTestCaseService.getInfoJenkins(testResult.getTestId()); - ApiDefinitionExecResult apiResult = apiDefinitionExecResultService.getInfo(apiTestCaseWithBLOBs.getLastResultId()); - //环境 - TestPlanApiCase testPlanApiCase = testPlanApiCaseService.getInfo(testResult.getTestId(), debugReportId); - String name = apiAutomationService.get(testPlanApiCase.getEnvironmentId()).getName(); - //执行人 - String userName = apiAutomationService.getUser(apiTestCaseWithBLOBs.getCreateUserId()); - //报告内容 - reportTask = new ApiTestReportVariable(); - if (null != apiResult) { - reportTask.setStatus(apiResult.getStatus()); - reportTask.setId(apiResult.getId()); - } else { - reportTask.setStatus(testPlanApiCase.getStatus()); - reportTask.setId(testPlanApiCase.getId()); - } - reportTask.setTriggerMode(TriggerMode.API.name()); - reportTask.setName(apiTestCaseWithBLOBs.getName()); - reportTask.setExecutor(userName); - reportTask.setExecutionTime(DateUtils.getTimeString(apiTestCaseWithBLOBs.getCreateTime())); - reportTask.setExecutionEnvironment(name); - //用例,定时,jenkins - } else if (StringUtils.equalsAny(runMode, ApiRunMode.API_PLAN.name(), ApiRunMode.SCHEDULE_API_PLAN.name())) { + //测试计划用例,定时,jenkins + } else if (StringUtils.equalsAny(runMode, ApiRunMode.API_PLAN.name(), ApiRunMode.SCHEDULE_API_PLAN.name(), ApiRunMode.JENKINS_API_PLAN.name())) { //测试计划定时任务-接口执行逻辑的话,需要同步测试计划的报告数据 if (StringUtils.equals(runMode, ApiRunMode.SCHEDULE_API_PLAN.name())) { apiDefinitionExecResultService.saveApiResultByScheduleTask(testResult, ApiRunMode.SCHEDULE_API_PLAN.name()); @@ -119,6 +97,14 @@ public class TestResultService { testPlanReportService.checkTestPlanStatus(testPlanReportId); } testPlanReportService.updateReport(testPlanReportIdList, ApiRunMode.SCHEDULE_API_PLAN.name(), ReportTriggerMode.SCHEDULE.name()); + } else if (StringUtils.equals(runMode, ApiRunMode.JENKINS_API_PLAN.name())) { + apiDefinitionExecResultService.saveApiResultByScheduleTask(testResult, ApiRunMode.JENKINS_API_PLAN.name()); + List testPlanReportIdList = new ArrayList<>(); + testPlanReportIdList.add(debugReportId); + for (String testPlanReportId : testPlanReportIdList) { // 更新每个测试计划的状态 + testPlanReportService.checkTestPlanStatus(testPlanReportId); + } + testPlanReportService.updateReport(testPlanReportIdList, ApiRunMode.JENKINS_API_PLAN.name(), ReportTriggerMode.API.name()); } else { apiDefinitionExecResultService.saveApiResult(testResult, ApiRunMode.API_PLAN.name(), TriggerMode.MANUAL.name()); } @@ -187,7 +173,7 @@ public class TestResultService { private void updateTestCaseStates(TestResult testResult, String testPlanScenarioId, String runMode) { try { if (StringUtils.equalsAny(runMode, ApiRunMode.API_PLAN.name(), ApiRunMode.SCHEDULE_API_PLAN.name(), - ApiRunMode.JENKINS_API_PLAN.name(), ApiRunMode.SCENARIO_PLAN.name(), ApiRunMode.SCHEDULE_SCENARIO_PLAN.name())) { + ApiRunMode.JENKINS_API_PLAN.name(), ApiRunMode.SCENARIO_PLAN.name(), ApiRunMode.SCHEDULE_SCENARIO_PLAN.name(), ApiRunMode.JENKINS_SCENARIO_PLAN.name())) { testResult.getScenarios().forEach(scenarioResult -> { if (scenarioResult != null && CollectionUtils.isNotEmpty(scenarioResult.getRequestResults())) { scenarioResult.getRequestResults().forEach(item -> { diff --git a/backend/src/main/java/io/metersphere/track/service/LoadReportStatusEvent.java b/backend/src/main/java/io/metersphere/track/service/LoadReportStatusEvent.java index 4229a5e17e..a1a467f2e4 100644 --- a/backend/src/main/java/io/metersphere/track/service/LoadReportStatusEvent.java +++ b/backend/src/main/java/io/metersphere/track/service/LoadReportStatusEvent.java @@ -33,7 +33,8 @@ public class LoadReportStatusEvent implements LoadTestFinishEvent { @Override public void execute(LoadTestReport loadTestReport) { if (StringUtils.equals(ReportTriggerMode.CASE.name(), loadTestReport.getTriggerMode()) - || StringUtils.equals(ReportTriggerMode.TEST_PLAN_SCHEDULE.name(), loadTestReport.getTriggerMode())) { + || StringUtils.equals(ReportTriggerMode.TEST_PLAN_SCHEDULE.name(), loadTestReport.getTriggerMode()) + || StringUtils.equals(ReportTriggerMode.TEST_PLAN_API.name(), loadTestReport.getTriggerMode())) { if (StringUtils.equalsAny(loadTestReport.getStatus(), PerformanceTestStatus.Completed.name(), PerformanceTestStatus.Error.name())) { updateLoadCaseStatus(loadTestReport); diff --git a/backend/src/main/java/io/metersphere/track/service/TestPlanReportService.java b/backend/src/main/java/io/metersphere/track/service/TestPlanReportService.java index 9ee74855d4..09d7323649 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestPlanReportService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestPlanReportService.java @@ -242,7 +242,8 @@ public class TestPlanReportService { String issuesInfo = null; //因为接口案例的定时任务是单个案例开线程运行, 所以要检查是否都执行完成。全部执行完成时才会进行统一整理 - if (StringUtils.equalsAny(triggerMode, ReportTriggerMode.SCHEDULE.name(), ReportTriggerMode.API.name()) && StringUtils.equalsAny(resourceRunMode, ApiRunMode.SCHEDULE_API_PLAN.name(), ApiRunMode.JENKINS_API_PLAN.name())) { + if (StringUtils.equalsAny(triggerMode, ReportTriggerMode.SCHEDULE.name(), ReportTriggerMode.API.name()) + && StringUtils.equalsAny(resourceRunMode, ApiRunMode.SCHEDULE_API_PLAN.name(), ApiRunMode.JENKINS_API_PLAN.name())) { List statusList = extTestPlanApiCaseMapper.getStatusByTestPlanId(testPlan.getId()); for (String status : statusList) { if (status == null) { @@ -250,6 +251,7 @@ public class TestPlanReportService { } } } else if (StringUtils.equals(ReportTriggerMode.TEST_PLAN_SCHEDULE.name(), triggerMode)) { + } testPlanReport.setEndTime(System.currentTimeMillis()); @@ -282,7 +284,7 @@ public class TestPlanReportService { && StringUtils.equalsAny(resourceRunMode, ApiRunMode.SCHEDULE_API_PLAN.name(), ApiRunMode.JENKINS_API_PLAN.name())) { testPlanReport.setIsApiCaseExecuting(false); } else if (StringUtils.equalsAny(triggerMode, ReportTriggerMode.SCHEDULE.name(), ReportTriggerMode.API.name()) - && StringUtils.equalsAny(resourceRunMode, ApiRunMode.SCHEDULE_SCENARIO_PLAN.name(), ApiRunMode.SCHEDULE_SCENARIO_PLAN.name())) { + && StringUtils.equalsAny(resourceRunMode, ApiRunMode.SCHEDULE_SCENARIO_PLAN.name(), ApiRunMode.JENKINS_SCENARIO_PLAN.name(), ApiRunMode.SCHEDULE_SCENARIO_PLAN.name())) { testPlanReport.setIsScenarioExecuting(false); } else if (StringUtils.equalsAny(triggerMode, ReportTriggerMode.SCHEDULE.name(), ReportTriggerMode.API.name()) && StringUtils.equalsAny(resourceRunMode, ApiRunMode.SCHEDULE_PERFORMANCE_TEST.name(), ApiRunMode.JENKINS_PERFORMANCE_TEST.name())) { @@ -519,10 +521,10 @@ public class TestPlanReportService { public void updatePerformanceTestStatus(TestPlanLoadCaseEventDTO eventDTO) { List testPlanReportId = extTestPlanMapper.findIdByPerformanceReportId(eventDTO.getReportId()); - if (StringUtils.equals(eventDTO.getTriggerMode(), ReportTriggerMode.SCHEDULE.name())) { - this.updateReport(testPlanReportId, ApiRunMode.SCHEDULE_PERFORMANCE_TEST.name(), eventDTO.getTriggerMode()); - } else { + if (StringUtils.equals(eventDTO.getTriggerMode(), ReportTriggerMode.API.name())) { this.updateReport(testPlanReportId, ApiRunMode.JENKINS_PERFORMANCE_TEST.name(), eventDTO.getTriggerMode()); + } else { + this.updateReport(testPlanReportId, ApiRunMode.SCHEDULE_PERFORMANCE_TEST.name(), eventDTO.getTriggerMode()); } } diff --git a/frontend/src/business/components/common/tableItem/ReportTriggerModeItem.vue b/frontend/src/business/components/common/tableItem/ReportTriggerModeItem.vue index 7d2c7cf487..f117cb80e7 100644 --- a/frontend/src/business/components/common/tableItem/ReportTriggerModeItem.vue +++ b/frontend/src/business/components/common/tableItem/ReportTriggerModeItem.vue @@ -1,5 +1,6 @@