diff --git a/backend/src/main/java/io/metersphere/api/jmeter/APIBackendListenerClient.java b/backend/src/main/java/io/metersphere/api/jmeter/APIBackendListenerClient.java index 72c1120b89..346a6add01 100644 --- a/backend/src/main/java/io/metersphere/api/jmeter/APIBackendListenerClient.java +++ b/backend/src/main/java/io/metersphere/api/jmeter/APIBackendListenerClient.java @@ -249,40 +249,6 @@ public class APIBackendListenerClient extends AbstractBackendListenerClient impl reportTask.setExecutor(userName); reportTask.setExecutionTime(executionTime); reportTask.setExecutionEnvironment(name); - } else if (StringUtils.equals(this.runMode, ApiRunMode.JENKINS_API_PLAN.name())) { - apiDefinitionService.addResult(testResult); - apiDefinitionExecResultService.saveApiResult(testResult, ApiRunMode.API_PLAN.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(); - //时间 - Long time = apiTestCaseWithBLOBs.getCreateTime(); - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - String executionTime = null; - String time_ = String.valueOf(time); - if (!time_.equals("null")) { - executionTime = sdf.format(new Date(Long.parseLong(time_))); - } - - //执行人 - String userName = apiAutomationService.getUser(apiTestCaseWithBLOBs.getCreateUserId()).getName(); - - //报告内容 - 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("API"); - reportTask.setName(apiTestCaseWithBLOBs.getName()); - reportTask.setExecutor(userName); - reportTask.setExecutionTime(executionTime); - reportTask.setExecutionEnvironment(name); //用例,定时,jenkins } else if (StringUtils.equalsAny(this.runMode, ApiRunMode.API_PLAN.name(), ApiRunMode.SCHEDULE_API_PLAN.name(), ApiRunMode.JENKINS_API_PLAN.name())) { apiDefinitionService.addResult(testResult); @@ -297,7 +263,7 @@ public class APIBackendListenerClient extends AbstractBackendListenerClient impl } testPlanReportService.updateReport(testPlanReportIdList, ApiRunMode.SCHEDULE_API_PLAN.name(), ReportTriggerMode.SCHEDULE.name()); } else if (StringUtils.equals(this.runMode, ApiRunMode.JENKINS_API_PLAN.name())) { - apiDefinitionExecResultService.saveApiResult(testResult, ApiRunMode.JENKINS_API_PLAN.name()); + apiDefinitionExecResultService.saveApiResultByScheduleTask(testResult, ApiRunMode.JENKINS_API_PLAN.name()); List testPlanReportIdList = new ArrayList<>(); testPlanReportIdList.add(debugReportId); for (String testPlanReportId : testPlanReportIdList) { // 更新每个测试计划的状态 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 31579e5682..4244f9dcdc 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionExecResultService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionExecResultService.java @@ -110,7 +110,7 @@ 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(); } @@ -129,7 +129,7 @@ public class ApiDefinitionExecResultService { saveResult.setStatus(status); String userID = null; - if (StringUtils.equals(type, ApiRunMode.SCHEDULE_API_PLAN.name())) { + if (StringUtils.equalsAny(type, ApiRunMode.SCHEDULE_API_PLAN.name(), ApiRunMode.JENKINS_API_PLAN.name())) { TestPlanApiCase apiCase = testPlanApiCaseService.getById(item.getName()); String scheduleCreateUser = testPlanService.findScheduleCreateUserById(apiCase.getTestPlanId()); userID = scheduleCreateUser; 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 d8ddb74a1b..a6b6dd79f7 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestPlanReportService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestPlanReportService.java @@ -248,7 +248,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) { @@ -256,6 +257,7 @@ public class TestPlanReportService { } } } else if (StringUtils.equals(ReportTriggerMode.TEST_PLAN_SCHEDULE.name(), triggerMode)) { + } testPlanReport.setEndTime(System.currentTimeMillis()); @@ -288,7 +290,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())) { 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())) { @@ -567,10 +569,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 @@