From fa3d750e2d506d29aa864608695847c8bac6290e Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Thu, 16 Sep 2021 18:25:12 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E5=9C=BA=E6=99=AF=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=8C=96)=20=E7=BB=88=E6=AD=A2=E6=89=A7=E8=A1=8C=E9=98=9F?= =?UTF-8?q?=E5=88=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/metersphere/api/service/ApiAutomationService.java | 5 +++++ .../api/service/task/SerialScenarioExecTask.java | 2 +- .../track/service/TestPlanApiCaseService.java | 5 +++++ .../track/service/task/SerialApiExecTask.java | 9 +++++++++ 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java index fd7209df14..3a085e99a3 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java @@ -1146,6 +1146,11 @@ public class ApiAutomationService { ApiTestEnvironmentService apiTestEnvironmentService = CommonBeanFactory.getBean(ApiTestEnvironmentService.class); HashTreeUtil hashTreeUtil = new HashTreeUtil(); for (String key : executeQueue.keySet()) { + // 终止执行 + if (MessageCache.terminationOrderDeque.contains(key)) { + MessageCache.terminationOrderDeque.remove(key); + break; + } reportIds.add(key); APIScenarioReportResult report = executeQueue.get(key).getReport(); if (StringUtils.isNotEmpty(serialReportId)) { diff --git a/backend/src/main/java/io/metersphere/api/service/task/SerialScenarioExecTask.java b/backend/src/main/java/io/metersphere/api/service/task/SerialScenarioExecTask.java index 1cc04e0673..d8a090704d 100644 --- a/backend/src/main/java/io/metersphere/api/service/task/SerialScenarioExecTask.java +++ b/backend/src/main/java/io/metersphere/api/service/task/SerialScenarioExecTask.java @@ -36,7 +36,7 @@ public class SerialScenarioExecTask implements Callable { try { if (MessageCache.terminationOrderDeque.contains(runModeDataDTO.getReport().getId())) { MessageCache.terminationOrderDeque.remove(runModeDataDTO.getReport().getId()); - return (T) report; + return null; } if (request.getConfig() != null && StringUtils.isNotBlank(request.getConfig().getResourcePoolId())) { jMeterService.runTest(runModeDataDTO.getTestId(), runModeDataDTO.getReport().getId(), request.getRunMode(), request.getPlanScenarioId(), request.getConfig()); diff --git a/backend/src/main/java/io/metersphere/track/service/TestPlanApiCaseService.java b/backend/src/main/java/io/metersphere/track/service/TestPlanApiCaseService.java index be66e5d2a2..2a5e883828 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestPlanApiCaseService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestPlanApiCaseService.java @@ -23,6 +23,7 @@ import io.metersphere.api.dto.definition.request.sampler.MsHTTPSamplerProxy; import io.metersphere.api.dto.definition.request.sampler.MsJDBCSampler; import io.metersphere.api.dto.definition.request.sampler.MsTCPSampler; import io.metersphere.api.jmeter.JMeterService; +import io.metersphere.api.jmeter.MessageCache; import io.metersphere.api.jmeter.ResourcePoolCalculation; import io.metersphere.api.service.ApiDefinitionExecResultService; import io.metersphere.api.service.ApiTestCaseService; @@ -420,6 +421,10 @@ public class TestPlanApiCaseService { public void run() { for (TestPlanApiCase testPlanApiCase : executeQueue.keySet()) { try { + if (MessageCache.terminationOrderDeque.contains(executeQueue.get(testPlanApiCase).getId())) { + MessageCache.terminationOrderDeque.remove(executeQueue.get(testPlanApiCase).getId()); + break; + } ApiDefinitionExecResult execResult = executeQueue.get(testPlanApiCase); execResult.setId(executeQueue.get(testPlanApiCase).getId()); execResult.setStatus(APITestStatus.Running.name()); diff --git a/backend/src/main/java/io/metersphere/track/service/task/SerialApiExecTask.java b/backend/src/main/java/io/metersphere/track/service/task/SerialApiExecTask.java index 9665fa7d9d..71658ff350 100644 --- a/backend/src/main/java/io/metersphere/track/service/task/SerialApiExecTask.java +++ b/backend/src/main/java/io/metersphere/track/service/task/SerialApiExecTask.java @@ -6,6 +6,7 @@ package io.metersphere.track.service.task; import io.metersphere.api.dto.RunModeDataDTO; import io.metersphere.api.dto.automation.RunModeConfig; import io.metersphere.api.jmeter.JMeterService; +import io.metersphere.api.jmeter.MessageCache; import io.metersphere.base.domain.ApiDefinitionExecResult; import io.metersphere.base.mapper.ApiDefinitionExecResultMapper; import io.metersphere.commons.constants.APITestStatus; @@ -33,6 +34,10 @@ public class SerialApiExecTask implements Callable { @Override public T call() { try { + if (MessageCache.terminationOrderDeque.contains(runModeDataDTO.getReport().getId())) { + MessageCache.terminationOrderDeque.remove(runModeDataDTO.getReport().getId()); + return null; + } if (config != null && StringUtils.isNotBlank(config.getResourcePoolId())) { jMeterService.runTest(runModeDataDTO.getTestId(), runModeDataDTO.getApiCaseId(), runMode, null, config); } else { @@ -48,6 +53,10 @@ public class SerialApiExecTask implements Callable { if (report != null && !report.getStatus().equals(APITestStatus.Running.name())) { break; } + if (MessageCache.terminationOrderDeque.contains(runModeDataDTO.getReport().getId())) { + MessageCache.terminationOrderDeque.remove(runModeDataDTO.getReport().getId()); + break; + } } // 执行失败了,恢复报告状态 if (index == 200 && report != null && report.getStatus().equals(APITestStatus.Running.name())) {