From dd92feeba2ba4238a0354e8f9c713ba59cb07357 Mon Sep 17 00:00:00 2001 From: song-tianyang Date: Wed, 2 Aug 2023 15:00:52 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=B5=8B=E8=AF=95=E8=AE=A1=E5=88=92):=20?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E8=AE=A1=E5=88=92=E4=B8=8D=E5=86=8D=E5=BC=BA?= =?UTF-8?q?=E5=88=B6=E5=85=B3=E8=81=94=E7=94=A8=E4=BE=8B=E6=97=B6=E9=80=89?= =?UTF-8?q?=E6=8B=A9=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --story=1012486 --user=宋天阳 【货车之家】接口场景包含跨项目步骤时取消跨项目环境必选&测试计划关联接口、UI测试时取消运行环境必选 https://www.tapd.cn/55049933/s/1401625 --- .../api/exec/api/ApiExecuteService.java | 12 +- .../service/ApiExecutionQueueService.java | 12 +- .../service/MockConfigService.java | 12 +- .../service/RedisTemplateService.java | 6 + .../automation/scenario/api/ApiRelevance.vue | 136 +- .../common/function/ApiFuncRelevance.vue | 78 +- .../frontend/src/i18n/lang/en-US.js | 7287 +++++++++-------- .../frontend/src/i18n/lang/zh-CN.js | 7027 ++++++++-------- .../frontend/src/i18n/lang/zh-TW.js | 7021 ++++++++-------- .../frontend/src/utils/constants.js | 751 +- .../constants/TestPlanExecuteCaseType.java | 5 + .../service/RedisTemplateService.java | 93 + .../plan/service/PerfQueueService.java | 17 +- .../listener/ExecReportListener.java | 4 + .../listener/ExecReportListenerTask.java | 25 +- .../plan/service/TestPlanExecuteService.java | 221 - .../plan/service/TestPlanReportService.java | 2 + .../plan/service/TestPlanService.java | 27 +- .../execute/TestPlanExecuteService.java | 352 + .../plan/common/TestPlanRunModeWithEnv.vue | 185 +- .../plan/components/ScheduleMaintain.vue | 400 +- .../business/plan/components/TestPlanList.vue | 800 +- .../business/plan/env/EnvSelectPopover.vue | 232 +- .../comonents/api/TestCaseApiRelevance.vue | 195 +- .../api/TestCaseScenarioRelevance.vue | 92 +- .../plan/view/comonents/api/TestPlanApi.vue | 132 +- .../view/comonents/api/module/ApiModule.vue | 87 +- .../ui/TestCaseUiScenarioRelevance.vue | 80 +- 28 files changed, 12863 insertions(+), 12428 deletions(-) create mode 100644 framework/sdk-parent/sdk/src/main/java/io/metersphere/commons/constants/TestPlanExecuteCaseType.java create mode 100644 framework/sdk-parent/sdk/src/main/java/io/metersphere/service/RedisTemplateService.java delete mode 100644 test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanExecuteService.java create mode 100644 test-track/backend/src/main/java/io/metersphere/plan/service/execute/TestPlanExecuteService.java 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 e2d5b23639..10fbfc8064 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 @@ -287,8 +287,16 @@ public class ApiExecuteService { TestPlanApiCaseExample example = new TestPlanApiCaseExample(); example.createCriteria().andTestPlanIdEqualTo(request.getTestPlanId()).andApiCaseIdEqualTo(request.getCaseId()); List list = testPlanApiCaseMapper.selectByExample(example); - request.setEnvironmentId(list.get(0).getEnvironmentId()); - element.setName(list.get(0).getId()); + if (CollectionUtils.isNotEmpty(list)) { + request.setEnvironmentId(list.get(0).getEnvironmentId()); + element.setName(list.get(0).getId()); + } else { + TestPlanApiCase apiCase = testPlanApiCaseMapper.selectByPrimaryKey(request.getCaseId()); + if (apiCase != null) { + request.setEnvironmentId(apiCase.getEnvironmentId()); + element.setName(request.getCaseId()); + } + } } else { element.setName(request.getCaseId()); } diff --git a/api-test/backend/src/main/java/io/metersphere/service/ApiExecutionQueueService.java b/api-test/backend/src/main/java/io/metersphere/service/ApiExecutionQueueService.java index 1c8379ad16..61fce3d6e4 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/ApiExecutionQueueService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/ApiExecutionQueueService.java @@ -11,10 +11,7 @@ import io.metersphere.base.mapper.ext.BaseApiExecutionQueueMapper; import io.metersphere.base.mapper.ext.ExtApiDefinitionExecResultMapper; import io.metersphere.base.mapper.ext.ExtApiScenarioReportMapper; import io.metersphere.base.mapper.plan.ext.ExtTestPlanApiCaseMapper; -import io.metersphere.commons.constants.ApiRunMode; -import io.metersphere.commons.constants.CommonConstants; -import io.metersphere.commons.constants.KafkaTopicConstants; -import io.metersphere.commons.constants.TestPlanReportStatus; +import io.metersphere.commons.constants.*; import io.metersphere.commons.enums.ApiReportStatus; import io.metersphere.commons.utils.BeanUtils; import io.metersphere.commons.utils.JSON; @@ -89,9 +86,11 @@ public class ApiExecutionQueueService { Map detailMap = new HashMap<>(); List queueDetails = new LinkedList<>(); // 初始化API/用例队列 + String redisLockType = TestPlanExecuteCaseType.SCENARIO.name(); if (StringUtils.equalsAnyIgnoreCase(type, ApiRunMode.DEFINITION.name(), ApiRunMode.API_PLAN.name())) { Map runMap = (Map) runObj; initApi(runMap, resQueue, config, detailMap, queueDetails); + redisLockType = TestPlanExecuteCaseType.API_CASE.name(); } // 初始化场景 else { @@ -101,11 +100,16 @@ public class ApiExecutionQueueService { if (CollectionUtils.isNotEmpty(queueDetails)) { extApiExecutionQueueMapper.sqlInsert(queueDetails); } + //redis移除key (执行测试计划时会添加key) + redisTemplateService.unlock(reportId, redisLockType, reportId); resQueue.setDetailMap(detailMap); LoggerUtil.info("报告【" + type + "】生成执行链结束", reportId); return resQueue; } + @Resource + private RedisTemplateService redisTemplateService; + private void initScenario(Map runMap, DBTestQueue resQueue, RunModeConfigDTO config, Map detailMap, List queueDetails) { final int[] sort = {0}; runMap.forEach((k, v) -> { diff --git a/api-test/backend/src/main/java/io/metersphere/service/MockConfigService.java b/api-test/backend/src/main/java/io/metersphere/service/MockConfigService.java index ea395ba200..778985153e 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/MockConfigService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/MockConfigService.java @@ -846,9 +846,8 @@ public class MockConfigService { if (project != null) { RequestMockParams requestMockParams = MockApiUtils.genRequestMockParamsFromHttpRequest(request, true); String urlSuffix = this.getUrlSuffix(project.getSystemId(), request); - LogUtil.info("Mock urlSuffix:{}", urlSuffix); - LogUtil.info("Mock requestHeaderMap:{}", requestHeaderMap); - LogUtil.info("Mock requestMockParams:{}", JSON.toJSONString(requestMockParams)); + LogUtil.info("Mock [" + url + "] Header:{}", requestHeaderMap); + LogUtil.info("Mock [" + url + "] request:{}", JSON.toJSONString(requestMockParams)); List qualifiedApiList = apiDefinitionService.preparedUrl(project.getId(), method, urlSuffix, requestHeaderMap.get(MockApiHeaders.MOCK_API_RESOURCE_ID)); for (ApiDefinitionWithBLOBs api : qualifiedApiList) { if (StringUtils.isEmpty(returnStr)) { @@ -872,6 +871,7 @@ public class MockConfigService { response.setStatus(404); returnStr = Translator.get("mock_warning"); } + LogUtil.info("Mock [" + url + "] response:{}", returnStr); return returnStr; } @@ -883,9 +883,8 @@ public class MockConfigService { RequestMockParams requestMockParams = MockApiUtils.genRequestMockParamsFromHttpRequest(request, false); String urlSuffix = this.getUrlSuffix(project.getSystemId(), request); - LogUtil.info("Mock urlSuffix:{}", urlSuffix); - LogUtil.info("Mock requestHeaderMap:{}", requestHeaderMap); - LogUtil.info("Mock requestMockParams:{}", JSON.toJSONString(requestMockParams)); + LogUtil.info("Mock [" + url + "] Header:{}", requestHeaderMap); + LogUtil.info("Mock [" + url + "] request:{}", JSON.toJSONString(requestMockParams)); List qualifiedApiList = apiDefinitionService.preparedUrl(project.getId(), method, urlSuffix, requestHeaderMap.get(MockApiHeaders.MOCK_API_RESOURCE_ID)); /* GET/DELETE 这种通过url穿参数的接口,在接口路径相同的情况下可能会出现这样的情况: @@ -919,6 +918,7 @@ public class MockConfigService { response.setStatus(404); returnStr = Translator.get("mock_warning"); } + LogUtil.info("Mock [" + url + "] response:{}", returnStr); return returnStr; } diff --git a/api-test/backend/src/main/java/io/metersphere/service/RedisTemplateService.java b/api-test/backend/src/main/java/io/metersphere/service/RedisTemplateService.java index e02d1e677f..509cf570f0 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/RedisTemplateService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/RedisTemplateService.java @@ -99,4 +99,10 @@ public class RedisTemplateService { } return false; } + + public void unlock(String testPlanReportId, String key, String value) { + String script = "if redis.call('get', KEYS[1]) == ARGV[1] then return redis.call('del', KEYS[1]) else return 0 end"; + RedisScript redisScript = new DefaultRedisScript<>(script, Long.class); + this.redisTemplate.execute(redisScript, Collections.singletonList(StringUtils.join(testPlanReportId, key)), new Object[]{value}); + } } diff --git a/api-test/frontend/src/business/automation/scenario/api/ApiRelevance.vue b/api-test/frontend/src/business/automation/scenario/api/ApiRelevance.vue index 90b4e2d306..e6156ec228 100644 --- a/api-test/frontend/src/business/automation/scenario/api/ApiRelevance.vue +++ b/api-test/frontend/src/business/automation/scenario/api/ApiRelevance.vue @@ -1,9 +1,9 @@