diff --git a/api-test/backend/src/main/java/io/metersphere/api/exec/api/ApiExecuteService.java b/api-test/backend/src/main/java/io/metersphere/api/exec/api/ApiExecuteService.java index 9df5094bff..145015f843 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/exec/api/ApiExecuteService.java +++ b/api-test/backend/src/main/java/io/metersphere/api/exec/api/ApiExecuteService.java @@ -26,6 +26,7 @@ import io.metersphere.commons.utils.*; import io.metersphere.dto.*; import io.metersphere.environment.service.BaseEnvironmentService; import io.metersphere.plugin.core.MsTestElement; +import io.metersphere.service.RemakeReportService; import io.metersphere.service.SystemParameterService; import io.metersphere.service.definition.TcpApiParamService; import io.metersphere.utils.LoggerUtil; @@ -65,6 +66,8 @@ public class ApiExecuteService { private TestPlanApiCaseMapper testPlanApiCaseMapper; @Resource private SystemParameterService systemParameterService; + @Resource + private RemakeReportService remakeReportService; public MsExecResponseDTO jenkinsRun(RunCaseRequest request) { ApiTestCaseWithBLOBs caseWithBLOBs = null; @@ -101,7 +104,6 @@ public class ApiExecuteService { caseWithBLOBs.setStatus(ApiReportStatus.RUNNING.name()); apiTestCaseMapper.updateByPrimaryKey(caseWithBLOBs); request.setReport(report); - if (StringUtils.isEmpty(request.getRunMode())) { request.setRunMode(ApiRunMode.DEFINITION.name()); } @@ -126,6 +128,7 @@ public class ApiExecuteService { jMeterService.verifyPool(testCaseWithBLOBs.getProjectId(), runModeConfigDTO); // 多态JSON普通转换会丢失内容,需要通过 ObjectMapper 获取 + JmeterRunRequestDTO runRequest = new JmeterRunRequestDTO(testCaseWithBLOBs.getId(), StringUtils.isEmpty(request.getReportId()) ? request.getId() : request.getReportId(), request.getRunMode(), null); if (testCaseWithBLOBs != null && StringUtils.isNotEmpty(testCaseWithBLOBs.getRequest())) { try { HashTree jmeterHashTree = this.generateHashTree(request, testCaseWithBLOBs, runModeConfigDTO); @@ -134,7 +137,7 @@ public class ApiExecuteService { } // 调用执行方法 - JmeterRunRequestDTO runRequest = new JmeterRunRequestDTO(testCaseWithBLOBs.getId(), StringUtils.isEmpty(request.getReportId()) ? request.getId() : request.getReportId(), request.getRunMode(), jmeterHashTree); + runRequest.setHashTree(jmeterHashTree); if (MapUtils.isNotEmpty(extendedParameters)) { runRequest.setExtendedParameters(extendedParameters); } @@ -147,20 +150,7 @@ public class ApiExecuteService { } jMeterService.run(runRequest); } catch (Exception ex) { - ApiDefinitionExecResult result = apiDefinitionExecResultMapper.selectByPrimaryKey(request.getReportId()); - if (result != null) { - result.setStatus(ApiReportStatus.ERROR.name()); - apiDefinitionExecResultMapper.updateByPrimaryKey(result); - ApiTestCaseWithBLOBs caseWithBLOBs = apiTestCaseMapper.selectByPrimaryKey(request.getCaseId()); - caseWithBLOBs.setStatus(ApiReportStatus.ERROR.name()); - apiTestCaseMapper.updateByPrimaryKey(caseWithBLOBs); - ApiDefinitionWithBLOBs apiDefinitionWithBLOBs = apiDefinitionMapper.selectByPrimaryKey(caseWithBLOBs.getApiDefinitionId()); - if (apiDefinitionWithBLOBs.getProtocol().equals("HTTP")) { - apiDefinitionWithBLOBs.setToBeUpdated(true); - apiDefinitionWithBLOBs.setToBeUpdateTime(System.currentTimeMillis()); - apiDefinitionMapper.updateByPrimaryKey(apiDefinitionWithBLOBs); - } - } + remakeReportService.testEnded(runRequest, ex.getMessage()); LogUtil.error(ex.getMessage(), ex); } } diff --git a/api-test/backend/src/main/java/io/metersphere/service/TestResultService.java b/api-test/backend/src/main/java/io/metersphere/service/TestResultService.java index d807920030..42ee56d565 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/TestResultService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/TestResultService.java @@ -6,6 +6,7 @@ import io.metersphere.api.jmeter.utils.ReportStatusUtil; import io.metersphere.base.domain.*; import io.metersphere.base.mapper.ApiDefinitionExecResultMapper; import io.metersphere.base.mapper.ApiScenarioMapper; +import io.metersphere.base.mapper.plan.TestPlanApiCaseMapper; import io.metersphere.base.mapper.plan.TestPlanApiScenarioMapper; import io.metersphere.commons.constants.*; import io.metersphere.commons.enums.ApiReportStatus; @@ -55,6 +56,8 @@ public class TestResultService { @Resource private ApiTestCaseService apiTestCaseService; @Resource + private TestPlanApiCaseMapper testPlanApiCaseMapper; + @Resource private TestPlanApiScenarioMapper testPlanApiScenarioMapper; @Resource private BaseShareInfoService baseShareInfoService; @@ -284,7 +287,13 @@ public class TestResultService { result.setContent(JSON.toJSONString(item)); apiDefinitionExecResultMapper.updateByPrimaryKeyWithBLOBs(result); - if (StringUtils.isNotEmpty(dto.getTestId())) { + if (StringUtils.equals(dto.getRunMode(), ApiRunMode.API_PLAN.name())) { + TestPlanApiCase testPlanApiCase = testPlanApiCaseMapper.selectByPrimaryKey(dto.getTestId()); + if (testPlanApiCase != null) { + testPlanApiCase.setStatus(ApiReportStatus.ERROR.name()); + testPlanApiCaseMapper.updateByPrimaryKey(testPlanApiCase); + } + } else if (StringUtils.isNotEmpty(dto.getTestId())) { ApiTestCaseWithBLOBs apiTestCase = new ApiTestCaseWithBLOBs(); apiTestCase.setLastResultId(dto.getReportId()); apiTestCase.setId(dto.getTestId()); diff --git a/api-test/backend/src/main/java/io/metersphere/service/plan/TestPlanApiCaseService.java b/api-test/backend/src/main/java/io/metersphere/service/plan/TestPlanApiCaseService.java index 47f878fbbd..d92c4b314f 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/plan/TestPlanApiCaseService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/plan/TestPlanApiCaseService.java @@ -805,6 +805,7 @@ public class TestPlanApiCaseService { request.setEnvironmentId(testPlanApiCase.getEnvironmentId()); request.setBloBs(apiCase); request.setReportId(reportId); + request.setTestPlanId(testPlanApiCase.getTestPlanId()); Map extendedParameters = new HashMap<>(); extendedParameters.put(ExtendedParameter.SYNC_STATUS, true); apiExecuteService.exec(request, extendedParameters); diff --git a/api-test/frontend/src/i18n/lang/en-US.js b/api-test/frontend/src/i18n/lang/en-US.js index 8f729112b1..9c6d0597be 100644 --- a/api-test/frontend/src/i18n/lang/en-US.js +++ b/api-test/frontend/src/i18n/lang/en-US.js @@ -45,7 +45,7 @@ const message = { no_data: 'No data', load_error: 'Load error', this_week: 'Week', - fake_error: 'Fake error', + fake_error: 'FakeError', executed_times_in_week: 'Executed in week', executed_times: 'Executed in history', covered: 'Covered', diff --git a/test-track/backend/src/main/resources/i18n/messages_en_US.properties b/test-track/backend/src/main/resources/i18n/messages_en_US.properties index b73aaa62ba..351c28dc12 100644 --- a/test-track/backend/src/main/resources/i18n/messages_en_US.properties +++ b/test-track/backend/src/main/resources/i18n/messages_en_US.properties @@ -227,6 +227,6 @@ plan_warning=The test plan does not have an associated executable use case test_plan_delete_exec_error=The test plan is being executed test_case_review_status_underway=Underway test_case_review_status_re_review=ReReview -api_status_fake_error=Fake error +api_status_fake_error=FakeError serial=Serial parallel=Parallel \ No newline at end of file