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())) {