From 8acefab96df3cdb84f478f891e42b09179a495fa Mon Sep 17 00:00:00 2001 From: AgAngle <1323481023@qq.com> Date: Thu, 11 Apr 2024 16:51:37 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=9C=BA=E6=99=AF=E5=89=8D=E7=BD=AE=E7=AD=89?= =?UTF-8?q?=E5=BE=85=E6=97=B6=E9=97=B4=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/dto/scenario/ScenarioOtherConfig.java | 5 --- .../api/job/ApiScenarioScheduleJob.java | 16 ++++++--- .../parser/jmeter/MsScenarioConverter.java | 35 +------------------ .../scenario/ApiScenarioBatchRunService.java | 7 ++-- .../service/scenario/ApiScenarioService.java | 34 +++++++++++++++--- .../ApiScenarioControllerTests.java | 1 - 6 files changed, 44 insertions(+), 54 deletions(-) diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/scenario/ScenarioOtherConfig.java b/backend/services/api-test/src/main/java/io/metersphere/api/dto/scenario/ScenarioOtherConfig.java index d93cba5dbf..4294d00ba2 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/dto/scenario/ScenarioOtherConfig.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/dto/scenario/ScenarioOtherConfig.java @@ -20,11 +20,6 @@ public class ScenarioOtherConfig { * 启用场景步骤等待时间 */ private Boolean enableStepWait = false; - /** - * 场景步骤等待时间 - * 每一个步骤执行后都会等待相应的时间 - */ - private Long stepWaitTime; /** * 失败策略 * @see FailureStrategy diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/job/ApiScenarioScheduleJob.java b/backend/services/api-test/src/main/java/io/metersphere/api/job/ApiScenarioScheduleJob.java index f542fc0457..f792648fcc 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/job/ApiScenarioScheduleJob.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/job/ApiScenarioScheduleJob.java @@ -7,8 +7,11 @@ import io.metersphere.api.dto.debug.ApiResourceRunRequest; import io.metersphere.api.dto.request.MsScenario; import io.metersphere.api.dto.scenario.ApiScenarioDetail; import io.metersphere.api.dto.scenario.ApiScenarioParseParam; +import io.metersphere.api.dto.scenario.ScenarioConfig; import io.metersphere.api.service.ApiExecuteService; import io.metersphere.api.service.scenario.ApiScenarioService; +import io.metersphere.project.api.processor.MsProcessor; +import io.metersphere.project.api.processor.TimeWaitingProcessor; import io.metersphere.sdk.constants.ApiBatchRunMode; import io.metersphere.sdk.constants.ApiExecuteRunMode; import io.metersphere.sdk.constants.TaskTriggerMode; @@ -22,10 +25,14 @@ import io.metersphere.system.uid.IDGenerator; import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.StringUtils; +import org.jetbrains.annotations.Nullable; import org.quartz.JobExecutionContext; import org.quartz.JobKey; import org.quartz.TriggerKey; +import java.util.List; +import java.util.concurrent.atomic.AtomicLong; + public class ApiScenarioScheduleJob extends BaseScheduleJob { @Override protected void businessExecute(JobExecutionContext context) { @@ -74,11 +81,8 @@ public class ApiScenarioScheduleJob extends BaseScheduleJob { scenarioReport.setRunMode(ApiBatchRunMode.PARALLEL.name()); scenarioReport.setPoolId(apiRunModeConfigDTO.getPoolId()); scenarioReport.setEnvironmentId(parseParam.getEnvironmentId()); - if (parseParam.getScenarioConfig() != null - && parseParam.getScenarioConfig().getOtherConfig() != null - && BooleanUtils.isTrue(parseParam.getScenarioConfig().getOtherConfig().getEnableStepWait())) { - scenarioReport.setWaitingTime(parseParam.getScenarioConfig().getOtherConfig().getStepWaitTime()); - } + scenarioReport.setWaitingTime(apiScenarioService.getGlobalWaitTime(parseParam.getScenarioConfig())); + apiScenarioService.initApiReport(apiScenarioDetail, scenarioReport); // 初始化报告步骤 @@ -87,6 +91,8 @@ public class ApiScenarioScheduleJob extends BaseScheduleJob { apiExecuteService.execute(runRequest, taskRequest, parseConfig); } + + public static JobKey getJobKey(String scenarioId) { return new JobKey(scenarioId, ApiScenarioScheduleJob.class.getName()); } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/MsScenarioConverter.java b/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/MsScenarioConverter.java index d2a0915c26..00064e7a21 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/MsScenarioConverter.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/MsScenarioConverter.java @@ -6,18 +6,15 @@ import io.metersphere.api.dto.ApiScenarioParamConfig; import io.metersphere.api.dto.request.MsScenario; import io.metersphere.api.dto.request.processors.MsProcessorConfig; import io.metersphere.api.dto.scenario.ScenarioConfig; -import io.metersphere.api.dto.scenario.ScenarioOtherConfig; import io.metersphere.api.dto.scenario.ScenarioStepConfig; import io.metersphere.api.dto.scenario.ScenarioVariable; import io.metersphere.api.parser.jmeter.processor.MsProcessorConverter; import io.metersphere.api.parser.jmeter.processor.MsProcessorConverterFactory; -import io.metersphere.api.parser.jmeter.processor.ScenarioTimeWaitingProcessorConverter; import io.metersphere.api.parser.jmeter.processor.assertion.AssertionConverterFactory; import io.metersphere.plugin.api.dto.ParameterConfig; import io.metersphere.plugin.api.spi.AbstractJmeterElementConverter; import io.metersphere.project.api.assertion.MsAssertion; import io.metersphere.project.api.processor.MsProcessor; -import io.metersphere.project.api.processor.TimeWaitingProcessor; import io.metersphere.project.dto.environment.EnvironmentConfig; import io.metersphere.project.dto.environment.EnvironmentInfoDTO; import io.metersphere.project.dto.environment.processors.EnvProcessorConfig; @@ -61,9 +58,6 @@ public class MsScenarioConverter extends AbstractJmeterElementConverter { processor.setProjectId(msScenario.getProjectId()); - MsProcessorConverter converter; - if (processor instanceof TimeWaitingProcessor) { - // 场景的的等待时间,需要包一层 debugSampler - converter = new ScenarioTimeWaitingProcessorConverter(); - } else { - converter = getConverterFunc.apply(processor.getClass()); - } - converter.parse(tree, processor, config); + getConverterFunc.apply(processor.getClass()).parse(tree, processor, config); }); } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/scenario/ApiScenarioBatchRunService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/scenario/ApiScenarioBatchRunService.java index 09a04c6289..cf34e55b0e 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/scenario/ApiScenarioBatchRunService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/scenario/ApiScenarioBatchRunService.java @@ -348,12 +348,11 @@ public class ApiScenarioBatchRunService { } private void updateReportWaitTime(String reportId, ApiScenarioParseParam parseParam) { - if (parseParam.getScenarioConfig() != null - && parseParam.getScenarioConfig().getOtherConfig() != null - && BooleanUtils.isTrue(parseParam.getScenarioConfig().getOtherConfig().getEnableStepWait())) { + Long globalWaitTime = apiScenarioService.getGlobalWaitTime(parseParam.getScenarioConfig()); + if (globalWaitTime != null) { ApiScenarioReport apiScenarioReport = new ApiScenarioReport(); apiScenarioReport.setId(reportId); - apiScenarioReport.setWaitingTime(parseParam.getScenarioConfig().getOtherConfig().getStepWaitTime()); + apiScenarioReport.setWaitingTime(globalWaitTime); apiScenarioReportMapper.updateByPrimaryKeySelective(apiScenarioReport); } } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/scenario/ApiScenarioService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/scenario/ApiScenarioService.java index 925af4241d..07f990f2d3 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/scenario/ApiScenarioService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/scenario/ApiScenarioService.java @@ -27,6 +27,8 @@ import io.metersphere.api.service.definition.ApiTestCaseService; import io.metersphere.api.utils.ApiDataUtils; import io.metersphere.api.utils.ApiScenarioBatchOperationUtils; import io.metersphere.plugin.api.spi.AbstractMsTestElement; +import io.metersphere.project.api.processor.MsProcessor; +import io.metersphere.project.api.processor.TimeWaitingProcessor; import io.metersphere.project.domain.FileAssociation; import io.metersphere.project.domain.FileMetadata; import io.metersphere.project.domain.Project; @@ -1390,11 +1392,8 @@ public class ApiScenarioService extends MoveNodeService { scenarioReport.setRunMode(ApiBatchRunMode.PARALLEL.name()); scenarioReport.setPoolId(poolId); scenarioReport.setEnvironmentId(parseParam.getEnvironmentId()); - if (parseParam.getScenarioConfig() != null - && parseParam.getScenarioConfig().getOtherConfig() != null - && BooleanUtils.isTrue(parseParam.getScenarioConfig().getOtherConfig().getEnableStepWait())) { - scenarioReport.setWaitingTime(parseParam.getScenarioConfig().getOtherConfig().getStepWaitTime()); - } + scenarioReport.setWaitingTime(getGlobalWaitTime(parseParam.getScenarioConfig())); + initApiReport(apiScenario, scenarioReport); // 初始化报告步骤 @@ -2850,4 +2849,29 @@ public class ApiScenarioService extends MoveNodeService { apiStepResourceInfo.setProjectName(project.getName()); return apiStepResourceInfo; } + + /** + * 获取场景前置的总等待时间 + * @param scenarioConfig + * @return + */ + public Long getGlobalWaitTime(ScenarioConfig scenarioConfig) { + Long waitTime = null; + if (scenarioConfig != null + && scenarioConfig.getPreProcessorConfig() != null + && scenarioConfig.getPreProcessorConfig().getProcessors() != null) { + waitTime = 0L; + for (MsProcessor processor : scenarioConfig + .getPreProcessorConfig() + .getProcessors()) { + if (processor instanceof TimeWaitingProcessor timeWaitingProcessor + && timeWaitingProcessor.getEnable() + && timeWaitingProcessor.getDelay() != null) { + waitTime += timeWaitingProcessor.getDelay(); + } + } + waitTime = waitTime > 0 ? waitTime : null; + } + return waitTime; + } } diff --git a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiScenarioControllerTests.java b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiScenarioControllerTests.java index 2467dc4c33..c699ca9897 100644 --- a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiScenarioControllerTests.java +++ b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiScenarioControllerTests.java @@ -456,7 +456,6 @@ public class ApiScenarioControllerTests extends BaseTest { responseCodeAssertion.setName("test"); scenarioConfig.getAssertionConfig().getAssertions().add(responseCodeAssertion); ScenarioOtherConfig scenarioOtherConfig = new ScenarioOtherConfig(); - scenarioOtherConfig.setStepWaitTime(1000L); scenarioOtherConfig.setFailureStrategy(ScenarioOtherConfig.FailureStrategy.CONTINUE.name()); scenarioOtherConfig.setEnableCookieShare(true); scenarioConfig.setOtherConfig(scenarioOtherConfig);