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 500ad4ab26..2b0b1c9b97 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 @@ -32,6 +32,7 @@ import io.metersphere.plugin.core.MsTestElement; import io.metersphere.service.definition.TcpApiParamService; import io.metersphere.utils.LoggerUtil; import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.collections.MapUtils; import org.apache.commons.lang3.StringUtils; import org.apache.jorphan.collections.HashTree; import org.apache.jorphan.collections.ListedHashTree; @@ -105,6 +106,10 @@ public class ApiExecuteService { } public MsExecResponseDTO exec(RunCaseRequest request) { + return exec(request, null); + } + + public MsExecResponseDTO exec(RunCaseRequest request, Map extendedParameters) { ApiTestCaseWithBLOBs testCaseWithBLOBs = request.getBloBs(); if (StringUtils.equals(request.getRunMode(), ApiRunMode.JENKINS_API_PLAN.name())) { testCaseWithBLOBs = apiTestCaseMapper.selectByPrimaryKey(request.getReportId()); @@ -123,6 +128,9 @@ public class ApiExecuteService { } // 调用执行方法 JmeterRunRequestDTO runRequest = new JmeterRunRequestDTO(testCaseWithBLOBs.getId(), StringUtils.isEmpty(request.getReportId()) ? request.getId() : request.getReportId(), request.getRunMode(), jmeterHashTree); + if (MapUtils.isNotEmpty(extendedParameters)) { + runRequest.setExtendedParameters(extendedParameters); + } jMeterService.run(runRequest); } catch (Exception ex) { ApiDefinitionExecResult result = apiDefinitionExecResultMapper.selectByPrimaryKey(request.getReportId()); 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 6166db7309..9f197b7ea0 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 @@ -783,6 +783,8 @@ public class TestPlanApiCaseService { request.setEnvironmentId(testPlanApiCase.getEnvironmentId()); request.setBloBs(apiCase); request.setReportId(reportId); - apiExecuteService.exec(request); + Map extendedParameters = new HashMap<>(); + extendedParameters.put("SYN_RES", true); + apiExecuteService.exec(request, extendedParameters); } } diff --git a/api-test/frontend/src/business/definition/components/response/RequestResultTail.vue b/api-test/frontend/src/business/definition/components/response/RequestResultTail.vue index 761c9cf107..d83ab519a4 100644 --- a/api-test/frontend/src/business/definition/components/response/RequestResultTail.vue +++ b/api-test/frontend/src/business/definition/components/response/RequestResultTail.vue @@ -10,6 +10,7 @@ import MsResponseResult from "../response/ResponseResult"; import MsRequestMetric from "../response/RequestMetric"; import {getApiReportDetail} from "../../../../api/definition-report"; +import {baseSocket} from "@/api/base-network"; export default { name: "MsRequestResultTail", @@ -51,12 +52,42 @@ export default { this.loading = true; getApiReportDetail(this.reportId).then(response => { this.loading = false; - if (response.data) { - this.report = JSON.parse(response.data.content); + let data = response.data; + if (data) { + this.report = JSON.parse(data.content); + if (data.status === 'RUNNING') { + this.loading = true; + this.socketSync(); + } } }); } }, + socketSync() { + this.websocket = baseSocket(this.reportId); + this.websocket.onmessage = this.onMessages; + this.websocket.onerror = this.onError; + }, + onError() { + this.$EventBus.$emit("API_TEST_ERROR", this.reportId); + }, + onMessages(e) { + if (e.data && e.data.startsWith("result_")) { + try { + let data = e.data.substring(7); + this.report = JSON.parse(data); + this.websocket.close(); + this.loading = false; + this.$EventBus.$emit("API_TEST_END", this.reportId); + } catch (e) { + console.log(e) // for debug + this.websocket.close(); + this.$EventBus.$emit("API_TEST_ERROR", this.reportId); + } + } else if (e.data === "MS_TEST_END") { + this.$EventBus.$emit("API_TEST_ERROR", this.reportId); + } + }, }, } diff --git a/framework/sdk-parent/frontend/src/components/MicroApp.vue b/framework/sdk-parent/frontend/src/components/MicroApp.vue index 691be17096..9b9f9389d7 100644 --- a/framework/sdk-parent/frontend/src/components/MicroApp.vue +++ b/framework/sdk-parent/frontend/src/components/MicroApp.vue @@ -37,7 +37,8 @@ export default { props: { defaultPath: this.to, routeParams: this.routeParams, - routeName: this.routeName + routeName: this.routeName, + eventBus: this.$EventBus } }; if (process.env.NODE_ENV !== 'development') { diff --git a/test-track/frontend/src/business/plan/view/comonents/api/TestPlanApiCaseList.vue b/test-track/frontend/src/business/plan/view/comonents/api/TestPlanApiCaseList.vue index d7a2d6af59..9f617aa8d7 100644 --- a/test-track/frontend/src/business/plan/view/comonents/api/TestPlanApiCaseList.vue +++ b/test-track/frontend/src/business/plan/view/comonents/api/TestPlanApiCaseList.vue @@ -157,7 +157,7 @@ - + { + this.runningReport.add(reportId); + this.$refs.apiCaseResult.open(reportId); + }); }, - socketSync(reportId) { - this.websocket = reportSocket(reportId); - this.websocket.onmessage = this.onMessages; - this.websocket.onerror = this.onError; - }, - onError(e) { - this.$error(e); - }, - onMessages(e) { - // 这里写自身逻辑 - if (e && e.data === "SUCCESS") { + handleTestEnd(reportId) { + if (this.runningReport.has(reportId)) { this.runRefresh(); + this.runningReport.delete(reportId); } }, - errorRefresh() { - this.rowLoading = ""; - }, handleBatchEdit() { this.$refs.batchEdit.open(this.condition.selectAll ? this.total : this.$refs.table.selectRows.size); this.$refs.batchEdit.setSelectRows(this.$refs.table.selectRows); @@ -576,9 +571,6 @@ export default { }); } }); - }, - getTestCase() { - }, batchEdit(form) { let param = {}; @@ -658,13 +650,7 @@ export default { } }, getReportResult(apiCase) { - apiDefinitionPlanReportGetByCaseId(apiCase.id) - .then(response => { - if (response.data) { - this.response = JSON.parse(response.data.content); - this.$refs.apiCaseResult.open(); - } - }); + this.$refs.apiCaseResult.openByCaseId(apiCase.id); }, getVersionOptions() { if (hasLicense()) { diff --git a/test-track/frontend/src/business/plan/view/comonents/api/TestPlanApiCaseResult.vue b/test-track/frontend/src/business/plan/view/comonents/api/TestPlanApiCaseResult.vue index f48fbbeb3d..1a96f00dee 100644 --- a/test-track/frontend/src/business/plan/view/comonents/api/TestPlanApiCaseResult.vue +++ b/test-track/frontend/src/business/plan/view/comonents/api/TestPlanApiCaseResult.vue @@ -1,30 +1,58 @@