From 0c444ec3288f6e61c13d521a17849480d87d8a16 Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Tue, 26 Jul 2022 18:04:57 +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=8D=E5=88=87=E6=8D=A2=E5=85=AC=E5=85=B1=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E6=BA=90=EF=BC=8C=E4=B8=8D=E5=90=8C=E5=8D=8F=E8=AE=AE?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E6=AD=A5=E9=AA=A4=E6=9C=AA=E8=B7=9F=E9=9A=8F?= =?UTF-8?q?=E5=8F=98=E6=9B=B4=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1015391 --user=赵勇 【接口测试】所有协议包含http和其他协议接口TEST页面添加前后置sql,右上角切换数据源时,不展开的前后置sql不会更新数据源 https://www.tapd.cn/55049933/s/1212544 --- .../api/service/ApiExecutionQueueService.java | 12 ++- .../definition/components/step/JmxStep.vue | 74 ++++++++++++++++++- 2 files changed, 82 insertions(+), 4 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/service/ApiExecutionQueueService.java b/backend/src/main/java/io/metersphere/api/service/ApiExecutionQueueService.java index 756a9cd21a..f16bd3e54a 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiExecutionQueueService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiExecutionQueueService.java @@ -404,6 +404,9 @@ public class ApiExecutionQueueService { continue; } // 检查是否已经超时 + ResultDTO dto = new ResultDTO(); + dto.setQueueId(item.getQueueId()); + dto.setTestId(item.getTestId()); if (StringUtils.equalsAnyIgnoreCase(queue.getRunMode(), ApiRunMode.SCENARIO.name(), ApiRunMode.SCENARIO_PLAN.name(), @@ -422,9 +425,6 @@ public class ApiExecutionQueueService { apiScenarioReportMapper.updateByPrimaryKeySelective(report); LoggerUtil.info("超时处理报告:" + report.getId()); - ResultDTO dto = new ResultDTO(); - dto.setQueueId(item.getQueueId()); - dto.setTestId(item.getTestId()); if (queue != null && StringUtils.equalsIgnoreCase(item.getType(), RunModeConstants.SERIAL.toString())) { // 删除串行资源锁 redisTemplate.delete(RunModeConstants.SERIAL.name() + "_" + dto.getReportId()); @@ -447,6 +447,12 @@ public class ApiExecutionQueueService { result.setStatus(ScenarioStatus.Timeout.name()); apiDefinitionExecResultMapper.updateByPrimaryKeySelective(result); executionQueueDetailMapper.deleteByPrimaryKey(item.getId()); + dto.setTestPlanReportId(queue.getReportId()); + dto.setReportId(queue.getReportId()); + dto.setRunMode(queue.getRunMode()); + dto.setRunType(item.getType()); + dto.setReportType(queue.getReportType()); + queueNext(dto); } } } diff --git a/frontend/src/business/components/api/definition/components/step/JmxStep.vue b/frontend/src/business/components/api/definition/components/step/JmxStep.vue index 805e3df516..735e30a4e3 100644 --- a/frontend/src/business/components/api/definition/components/step/JmxStep.vue +++ b/frontend/src/business/components/api/definition/components/step/JmxStep.vue @@ -132,12 +132,13 @@ import {createComponent} from "../jmeter/components"; import MsApiAssertions from "../assertion/ApiAssertions"; import MsApiExtract from "../extract/ApiExtract"; import {Assertions, Body, ConstantTimer, Extract, KeyValue} from "../../model/ApiTestModel"; -import {getUUID} from "@/common/js/utils"; +import {getUUID, getCurrentProjectID} from "@/common/js/utils"; import BatchAddParameter from "../basis/BatchAddParameter"; import MsJsr233Processor from "../../../automation/scenario/component/Jsr233Processor"; import MsConstantTimer from "../../../automation/scenario/component/ConstantTimer"; import MsJdbcProcessor from "@/business/components/api/automation/scenario/component/JDBCProcessor"; import {TYPE_TO_C} from "@/business/components/api/automation/scenario/Setting"; +import {parseEnvironment} from "../../model/EnvironmentModel"; export default { name: "MsJmxStep", @@ -177,6 +178,14 @@ export default { default: false } }, + watch: { + // 接口/用例 右上角公共环境监听 + '$store.state.useEnvironment': function () { + if (this.request.hashTree && this.request.hashTree.length > 0 && !this.scenarioId) { + this.setSubset(this.request.hashTree, this.$store.state.useEnvironment); + } + }, + }, data() { let validateURL = (rule, value, callback) => { try { @@ -220,6 +229,7 @@ export default { isReloadData: false, isBodyShow: true, dialogVisible: false, + environments: [], } }, created() { @@ -271,6 +281,67 @@ export default { this.sort(); this.reload(); }, + setSubset(scenarioDefinition, env) { + for (let i in scenarioDefinition) { + let typeArray = ["JDBCPostProcessor", "JDBCSampler", "JDBCPreProcessor"] + if (typeArray.indexOf(scenarioDefinition[i].type) !== -1) { + // 找到原始数据源名称 + this.getTargetSource(scenarioDefinition[i]) + scenarioDefinition[i].environmentId = env; + this.setSameSourceId(env, scenarioDefinition[i]) + } + if (scenarioDefinition[i].hashTree !== undefined && scenarioDefinition[i].hashTree.length > 0) { + this.setSubset(scenarioDefinition[i].hashTree, env); + } + } + }, + getEnvs() { + if (!this.scenarioId) { + let projectId = this.request.projectId ? this.request.projectId : getCurrentProjectID(); + this.result = this.$get('/api/environment/list/' + projectId, response => { + this.environments = response.data; + this.environments.forEach(environment => { + parseEnvironment(environment); + }); + }); + } + }, + getTargetSource(obj) { + this.environments.forEach(environment => { + // 找到原始环境和数据源名称 + if (environment.id === obj.environmentId) { + if (environment.config && environment.config.databaseConfigs) { + environment.config.databaseConfigs.forEach(item => { + if (item.id === obj.dataSourceId) { + obj.targetDataSourceName = item.name; + } + }); + } + } + }); + }, + setSameSourceId(envId, obj) { + let currentEnvironment; + for (let i in this.environments) { + if (this.environments[i].id === envId) { + currentEnvironment = this.environments[i]; + break; + } + } + let isSame = false; + if (currentEnvironment && currentEnvironment.config && currentEnvironment.config.databaseConfigs) { + currentEnvironment.config.databaseConfigs.forEach(item => { + // 按照名称匹配 + if (item.name === obj.targetDataSourceName) { + obj.dataSourceId = item.id; + isSame = true; + } + }); + if (!isSame && currentEnvironment.config.databaseConfigs.length > 0) { + obj.dataSourceId = currentEnvironment.config.databaseConfigs[0].id; + } + } + }, setOwnEnvironment(scenarioDefinition) { for (let i in scenarioDefinition) { let typeArray = ["JDBCPostProcessor", "JDBCSampler", "JDBCPreProcessor"] @@ -455,6 +526,7 @@ export default { this.request.arguments = []; } this.sort(); + this.getEnvs(); }, sort() { let index = 1;