From e0309cbe2d4e4bb6cb9495c45a7c9e468e6579cd Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Wed, 7 Dec 2022 15:27:46 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8Dk8s=E8=B5=84=E6=BA=90=E6=B1=A0=E6=B2=A1?= =?UTF-8?q?=E6=9C=89=E5=8F=AF=E7=94=A8=E7=9A=84pod=E6=97=A0=E6=8F=90?= =?UTF-8?q?=E7=A4=BA=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1020710 --user=赵勇 【接口测试】K8S资源池异常时接口测试执行失败未正常处理 https://www.tapd.cn/55049933/s/1313865 --- .../api/exec/engine/KubernetesTestEngine.java | 11 +++++++++++ .../automation/report/SyncApiReportDetail.vue | 8 ++++++++ .../business/automation/scenario/EditApiScenario.vue | 5 +++++ .../automation/scenario/component/LoopController.vue | 7 +++++++ .../src/business/definition/components/Run.vue | 6 +++++- .../definition/components/debug/DebugDubboPage.vue | 6 +++++- .../definition/components/debug/DebugHttpPage.vue | 6 +++++- .../definition/components/debug/DebugJdbcPage.vue | 6 +++++- .../definition/components/debug/DebugTcpPage.vue | 6 +++++- api-test/frontend/src/i18n/lang/en-US.js | 2 ++ api-test/frontend/src/i18n/lang/zh-CN.js | 1 + api-test/frontend/src/i18n/lang/zh-TW.js | 1 + 12 files changed, 60 insertions(+), 5 deletions(-) diff --git a/api-test/backend/src/main/java/io/metersphere/api/exec/engine/KubernetesTestEngine.java b/api-test/backend/src/main/java/io/metersphere/api/exec/engine/KubernetesTestEngine.java index 0a817a9d52..c686f5a1c7 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/exec/engine/KubernetesTestEngine.java +++ b/api-test/backend/src/main/java/io/metersphere/api/exec/engine/KubernetesTestEngine.java @@ -2,12 +2,14 @@ package io.metersphere.api.exec.engine; import io.fabric8.kubernetes.api.model.Pod; import io.fabric8.kubernetes.client.KubernetesClient; +import io.metersphere.api.dto.MsgDTO; import io.metersphere.base.domain.TestResource; import io.metersphere.commons.constants.ApiRunMode; import io.metersphere.commons.constants.ExtendedParameter; import io.metersphere.commons.exception.MSException; import io.metersphere.commons.utils.JSON; import io.metersphere.commons.utils.LogUtil; +import io.metersphere.commons.utils.WebSocketUtil; import io.metersphere.dto.JmeterRunRequestDTO; import io.metersphere.utils.LoggerUtil; import io.metersphere.xpack.resourcepool.engine.provider.ClientCredential; @@ -21,6 +23,7 @@ import java.util.Set; public class KubernetesTestEngine extends AbstractEngine { private JmeterRunRequestDTO runRequest; + private final String DEBUG_ERROR = "DEBUG_ERROR"; // 初始化API调用 public KubernetesTestEngine(JmeterRunRequestDTO runRequest) { @@ -77,6 +80,14 @@ public class KubernetesTestEngine extends AbstractEngine { command.append(StringUtils.SPACE).append("http://127.0.0.1:8082/jmeter/").append(path); KubernetesApiExec.newExecWatch(client, clientCredential.getNamespace(), pod.getMetadata().getName(), command.toString()); } catch (Exception e) { + MsgDTO dto = new MsgDTO(); + dto.setExecEnd(false); + dto.setContent(DEBUG_ERROR); + dto.setReportId("send." + runRequest.getReportId()); + dto.setToReport(runRequest.getReportId()); + LoggerUtil.debug("send. " + runRequest.getReportId()); + WebSocketUtil.sendMessageSingle(dto); + WebSocketUtil.onClose(runRequest.getReportId()); LoggerUtil.error("当前报告:【" + runRequest.getReportId() + "】资源:【" + runRequest.getTestId() + "】CURL失败:", e); MSException.throwException(e); } diff --git a/api-test/frontend/src/business/automation/report/SyncApiReportDetail.vue b/api-test/frontend/src/business/automation/report/SyncApiReportDetail.vue index 0f2d9223db..744cfd51c8 100644 --- a/api-test/frontend/src/business/automation/report/SyncApiReportDetail.vue +++ b/api-test/frontend/src/business/automation/report/SyncApiReportDetail.vue @@ -503,6 +503,14 @@ export default { this.runningEvaluation(e.data); this.sort(this.fullTreeNodes); } + if (e && e.data === 'DEBUG_ERROR') { + this.$error(this.$t('api_definition.debug_pool_warning')); + this.messageWebSocket.close(); + this.cleanHeartBeat(); + this.$EventBus.$emit('hide', this.scenarioId); + this.$emit('refresh', this.debugResult); + } + if (e.data && e.data.indexOf('MS_TEST_END') !== -1) { this.getReport(); this.messageWebSocket.close(); diff --git a/api-test/frontend/src/business/automation/scenario/EditApiScenario.vue b/api-test/frontend/src/business/automation/scenario/EditApiScenario.vue index c9d998b734..6b0073f3fd 100644 --- a/api-test/frontend/src/business/automation/scenario/EditApiScenario.vue +++ b/api-test/frontend/src/business/automation/scenario/EditApiScenario.vue @@ -1233,6 +1233,11 @@ export default { if (e && e.data === 'CONN_SUCCEEDED') { this.run(); } + if (e && e.data === 'DEBUG_ERROR') { + this.$error(this.$t('api_definition.debug_pool_warning')); + this.messageWebSocket.close(); + this.errorRefresh(); + } if (e.data && e.data.startsWith('result_')) { let data = JSON.parse(e.data.substring(7)); this.reqTotal += 1; diff --git a/api-test/frontend/src/business/automation/scenario/component/LoopController.vue b/api-test/frontend/src/business/automation/scenario/component/LoopController.vue index 31329bb3be..498f699aea 100644 --- a/api-test/frontend/src/business/automation/scenario/component/LoopController.vue +++ b/api-test/frontend/src/business/automation/scenario/component/LoopController.vue @@ -292,6 +292,13 @@ export default { if (e && e.data === 'CONN_SUCCEEDED') { this.runDebug(); } + if (e && e.data === 'DEBUG_ERROR') { + this.$error(this.$t('api_definition.debug_pool_warning')); + this.loading = false; + this.node.expanded = true; + this.messageWebSocket.close(); + this.reload(); + } if (e.data && e.data.startsWith('result_')) { let data = JSON.parse(e.data.substring(7)); this.debugCode(data); diff --git a/api-test/frontend/src/business/definition/components/Run.vue b/api-test/frontend/src/business/definition/components/Run.vue index 7656c91976..3273067877 100644 --- a/api-test/frontend/src/business/definition/components/Run.vue +++ b/api-test/frontend/src/business/definition/components/Run.vue @@ -62,7 +62,11 @@ export default { if (e && e.data === 'CONN_SUCCEEDED') { this.run(); } - + if (e && e.data === 'DEBUG_ERROR') { + this.$error(this.$t('api_definition.debug_pool_warning')); + this.websocket.close(); + this.$emit('errorRefresh', ''); + } if (e.data && e.data.startsWith('result_')) { try { let data = e.data.substring(7); diff --git a/api-test/frontend/src/business/definition/components/debug/DebugDubboPage.vue b/api-test/frontend/src/business/definition/components/debug/DebugDubboPage.vue index 460e437732..7234dc5b99 100644 --- a/api-test/frontend/src/business/definition/components/debug/DebugDubboPage.vue +++ b/api-test/frontend/src/business/definition/components/debug/DebugDubboPage.vue @@ -53,6 +53,7 @@ :isStop="isStop" :run-data="runData" @runRefresh="runRefresh" + @errorRefresh="errorRefresh" ref="runTest" />
@@ -188,11 +189,14 @@ export default { this.reportId = getUUID().substring(0, 8); }, runRefresh(data) { - this.responseData = data; + this.responseData = data || { type: 'DUBBO', responseResult: {}, subRequestResults: [] }; this.loading = false; this.isStop = false; this.$refs.debugResult.reload(); }, + errorRefresh() { + this.runRefresh(); + }, saveAsApi() { let obj = { request: this.request }; obj.request.id = getUUID(); diff --git a/api-test/frontend/src/business/definition/components/debug/DebugHttpPage.vue b/api-test/frontend/src/business/definition/components/debug/DebugHttpPage.vue index 70ce51561b..36eebd61da 100644 --- a/api-test/frontend/src/business/definition/components/debug/DebugHttpPage.vue +++ b/api-test/frontend/src/business/definition/components/debug/DebugHttpPage.vue @@ -74,6 +74,7 @@ :isStop="isStop" :run-data="runData" @runRefresh="runRefresh" + @errorRefresh="errorRefresh" ref="runTest" />
@@ -240,13 +241,16 @@ export default { this.$emit('refreshModule'); }, runRefresh(data) { - this.responseData = data; + this.responseData = data || { type: 'HTTP', responseResult: {}, subRequestResults: [] }; this.loading = false; this.isStop = false; if (this.$refs.debugResult) { this.$refs.debugResult.reload(); } }, + errorRefresh() { + this.runRefresh(); + }, saveAsApi() { this.$refs['debugForm'].validate((valid) => { if (valid) { diff --git a/api-test/frontend/src/business/definition/components/debug/DebugJdbcPage.vue b/api-test/frontend/src/business/definition/components/debug/DebugJdbcPage.vue index c9952d2357..a8fded8fe4 100644 --- a/api-test/frontend/src/business/definition/components/debug/DebugJdbcPage.vue +++ b/api-test/frontend/src/business/definition/components/debug/DebugJdbcPage.vue @@ -54,6 +54,7 @@ :isStop="isStop" :run-data="runData" @runRefresh="runRefresh" + @errorRefresh="errorRefresh" ref="runTest" />
@@ -194,13 +195,16 @@ export default { this.reportId = getUUID().substring(0, 8); }, runRefresh(data) { - this.responseData = data; + this.responseData = data || { type: 'JDBC', responseResult: {}, subRequestResults: [] }; this.loading = false; this.isStop = false; if (this.$refs.debugResult) { this.$refs.debugResult.reload(); } }, + errorRefresh() { + this.runRefresh(); + }, saveAsApi() { let obj = { request: this.request }; obj.request.id = getUUID(); diff --git a/api-test/frontend/src/business/definition/components/debug/DebugTcpPage.vue b/api-test/frontend/src/business/definition/components/debug/DebugTcpPage.vue index f3dc1874da..f89e3bc741 100644 --- a/api-test/frontend/src/business/definition/components/debug/DebugTcpPage.vue +++ b/api-test/frontend/src/business/definition/components/debug/DebugTcpPage.vue @@ -56,6 +56,7 @@ :isStop="isStop" :run-data="runData" @runRefresh="runRefresh" + @errorRefresh="errorRefresh" ref="runTest" />
@@ -193,13 +194,16 @@ export default { this.reportId = getUUID().substring(0, 8); }, runRefresh(data) { - this.responseData = data; + this.responseData = data || { type: 'TCP', responseResult: {}, subRequestResults: [] }; this.loading = false; this.isStop = false; if (this.$refs.debugResult) { this.$refs.debugResult.reload(); } }, + errorRefresh() { + this.runRefresh(); + }, saveAsApi() { let obj = { request: this.request }; obj.request.id = getUUID(); diff --git a/api-test/frontend/src/i18n/lang/en-US.js b/api-test/frontend/src/i18n/lang/en-US.js index 83b1890d7e..2f2ddaee5c 100644 --- a/api-test/frontend/src/i18n/lang/en-US.js +++ b/api-test/frontend/src/i18n/lang/en-US.js @@ -7,6 +7,8 @@ const message = { please_add_api_case: 'Please add api case', }, api_definition: { + debug_pool_warning: + 'Failed to call the resource pool, please check whether the configuration of the resource pool is normal', document: { name: 'name', value: 'value', diff --git a/api-test/frontend/src/i18n/lang/zh-CN.js b/api-test/frontend/src/i18n/lang/zh-CN.js index 4e1a61a643..f6d61c2b82 100644 --- a/api-test/frontend/src/i18n/lang/zh-CN.js +++ b/api-test/frontend/src/i18n/lang/zh-CN.js @@ -7,6 +7,7 @@ const message = { please_add_api_case: '请先添加接口用例', }, api_definition: { + debug_pool_warning: '调用资源池执行失败,请检查资源池是否配置正常', document: { name: '名称', value: '值', diff --git a/api-test/frontend/src/i18n/lang/zh-TW.js b/api-test/frontend/src/i18n/lang/zh-TW.js index 4ea954a626..6240b7c732 100644 --- a/api-test/frontend/src/i18n/lang/zh-TW.js +++ b/api-test/frontend/src/i18n/lang/zh-TW.js @@ -7,6 +7,7 @@ const message = { please_add_api_case: '请先添加接口用例', }, api_definition: { + debug_pool_warning: '調用資源池執行失敗,請檢查資源池是否配置正常', document: { name: '名稱', value: '值',