diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/invoker/ApiExecuteCallbackServiceInvoker.java b/backend/services/api-test/src/main/java/io/metersphere/api/invoker/ApiExecuteCallbackServiceInvoker.java index 70c529065f..a0121f142e 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/invoker/ApiExecuteCallbackServiceInvoker.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/invoker/ApiExecuteCallbackServiceInvoker.java @@ -35,8 +35,8 @@ public class ApiExecuteCallbackServiceInvoker { getCallbackService(getApiExecuteResourceType(resourceType)).executeNextTask(queue, queueDetail); } - public static void executeNextCollection(String resourceType, String collectionQueueId) { - getCallbackService(getApiExecuteResourceType(resourceType)).executeNextCollection(collectionQueueId); + public static void executeNextCollection(String resourceType, String collectionQueueId, boolean isStopOnFailure) { + getCallbackService(getApiExecuteResourceType(resourceType)).executeNextCollection(collectionQueueId, isStopOnFailure); } public static void stopCollectionOnFailure(String resourceType, String collectionQueueId) { diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/listener/MessageListener.java b/backend/services/api-test/src/main/java/io/metersphere/api/listener/MessageListener.java index b8fa162841..e433ea4f96 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/listener/MessageListener.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/listener/MessageListener.java @@ -95,7 +95,7 @@ public class MessageListener { } if (BooleanUtils.isTrue(dto.getChildCollectionExecuteOver()) || isStopOnFailure(dto)) { // 如果当前测试集执行完了,或者当前测试集失败停止了,执行下一个测试集 - ApiExecuteCallbackServiceInvoker.executeNextCollection(dto.getResourceType(), dto.getParentQueueId()); + ApiExecuteCallbackServiceInvoker.executeNextCollection(dto.getResourceType(), dto.getParentQueueId(),isStopOnFailure(dto)); } } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/ApiExecuteCallbackService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/ApiExecuteCallbackService.java index 6809e88b98..94a6756aac 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/ApiExecuteCallbackService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/ApiExecuteCallbackService.java @@ -27,7 +27,8 @@ public interface ApiExecuteCallbackService { * 测试集下用例执行完成时回调 * @param collectionQueueId */ - default void executeNextCollection(String collectionQueueId) {} + default void executeNextCollection(String collectionQueueId, boolean isStopOnFailure) { + } /** * 失败停止时,处理 parentQueue diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanCollectionMapper.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanCollectionMapper.java index 5c88d104d6..c355b57c5e 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanCollectionMapper.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanCollectionMapper.java @@ -15,4 +15,6 @@ public interface ExtTestPlanCollectionMapper { TestPlanCollectionEnvDTO selectFirstCollectionEnv(@Param("type") String type, @Param("parentId") String parentId, @Param("testPlanId") String testPlanId); String selectDefaultCollectionId(@Param("testPlanId")String newTestPlanId,@Param("type") String key); + + boolean getParentStopOnFailure(String collectionId); } diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanCollectionMapper.xml b/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanCollectionMapper.xml index 8737e01837..f986b3d667 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanCollectionMapper.xml +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanCollectionMapper.xml @@ -59,4 +59,9 @@ ORDER BY pos limit 1 + \ No newline at end of file diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/PlanRunApiCaseExecuteCallbackService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/PlanRunApiCaseExecuteCallbackService.java index ca145eeab7..a4a6b3356f 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/PlanRunApiCaseExecuteCallbackService.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/PlanRunApiCaseExecuteCallbackService.java @@ -52,7 +52,7 @@ public class PlanRunApiCaseExecuteCallbackService implements ApiExecuteCallbackS * @param parentQueueId */ @Override - public void executeNextCollection(String parentQueueId) { - testPlanExecuteService.collectionExecuteQueueFinish(parentQueueId); + public void executeNextCollection(String parentQueueId, boolean isStopOnFailure) { + testPlanExecuteService.collectionExecuteQueueFinish(parentQueueId, isStopOnFailure); } } diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/PlanRunApiScenarioExecuteCallbackService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/PlanRunApiScenarioExecuteCallbackService.java index 59789321fe..1e737e1a92 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/PlanRunApiScenarioExecuteCallbackService.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/PlanRunApiScenarioExecuteCallbackService.java @@ -52,7 +52,7 @@ public class PlanRunApiScenarioExecuteCallbackService implements ApiExecuteCallb * @param parentQueueId */ @Override - public void executeNextCollection(String parentQueueId) { - testPlanExecuteService.collectionExecuteQueueFinish(parentQueueId); + public void executeNextCollection(String parentQueueId, boolean isStopOnFailure) { + testPlanExecuteService.collectionExecuteQueueFinish(parentQueueId, isStopOnFailure); } } diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiCaseExecuteCallbackService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiCaseExecuteCallbackService.java index d5d6211fcf..f3c84f9e3a 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiCaseExecuteCallbackService.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiCaseExecuteCallbackService.java @@ -48,10 +48,9 @@ public class TestPlanApiCaseExecuteCallbackService implements ApiExecuteCallback /** * 批量串行的测试集执行时 * 测试集下用例执行完成时回调 - * @param parentQueueId */ @Override - public void executeNextCollection(String parentQueueId) { + public void executeNextCollection(String parentQueueId, boolean isStopOnFailure) { testPlanApiCaseBatchRunService.executeNextCollection(parentQueueId); } diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiScenarioExecuteCallbackService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiScenarioExecuteCallbackService.java index e96cfa8d69..c47abd6c67 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiScenarioExecuteCallbackService.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiScenarioExecuteCallbackService.java @@ -51,7 +51,7 @@ public class TestPlanApiScenarioExecuteCallbackService implements ApiExecuteCall * @param collectionQueueId */ @Override - public void executeNextCollection(String collectionQueueId) { + public void executeNextCollection(String collectionQueueId, boolean isStopOnFailure) { testPlanApiScenarioBatchRunService.executeNextCollection(collectionQueueId); } diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanExecuteService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanExecuteService.java index c6eeab4b2d..b23ff63de2 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanExecuteService.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanExecuteService.java @@ -5,10 +5,7 @@ import io.metersphere.plan.domain.*; import io.metersphere.plan.dto.request.TestPlanBatchExecuteRequest; import io.metersphere.plan.dto.request.TestPlanExecuteRequest; import io.metersphere.plan.dto.request.TestPlanReportGenRequest; -import io.metersphere.plan.mapper.TestPlanCollectionMapper; -import io.metersphere.plan.mapper.TestPlanConfigMapper; -import io.metersphere.plan.mapper.TestPlanMapper; -import io.metersphere.plan.mapper.TestPlanReportMapper; +import io.metersphere.plan.mapper.*; import io.metersphere.sdk.constants.*; import io.metersphere.sdk.dto.queue.TestPlanExecutionQueue; import io.metersphere.sdk.exception.MSException; @@ -35,6 +32,8 @@ public class TestPlanExecuteService { @Resource private TestPlanMapper testPlanMapper; @Resource + private ExtTestPlanCollectionMapper extTestPlanCollectionMapper; + @Resource private TestPlanConfigMapper testPlanConfigMapper; @Resource private TestPlanService testPlanService; @@ -424,7 +423,7 @@ public class TestPlanExecuteService { if (execOver) { // 如果没有要执行的用例(可能会出现空测试集的情况),直接调用回调 - collectionExecuteQueueFinish(queueId); + collectionExecuteQueueFinish(queueId, false); } } @@ -433,7 +432,7 @@ public class TestPlanExecuteService { } //测试集执行完成 - public void collectionExecuteQueueFinish(String paramQueueId) { + public void collectionExecuteQueueFinish(String paramQueueId, boolean isStopOnFailure) { LogUtils.info("收到测试集执行完成的信息: [{}]", paramQueueId); String queueID = paramQueueId; String[] queueIdArr = queueID.split("_"); @@ -454,13 +453,13 @@ public class TestPlanExecuteService { boolean execError = false; try { LogUtils.info("测试集该节点的串行执行完成! --- 队列ID[{}],队列类型[{}],开始执行下一个队列:ID[{}],类型[{}]", queueID, queueType, nextQueue.getQueueId(), nextQueue.getQueueType()); - this.executeNextNode(nextQueue); + this.executeNextNode(nextQueue, isStopOnFailure); } catch (Exception e) { Log.error("测试集下一个节点执行失败!", e); execError = true; } if (execError) { - this.collectionExecuteQueueFinish(nextQueue.getQueueId()); + this.collectionExecuteQueueFinish(nextQueue.getQueueId(), true); } } else { //当前测试集执行完毕 @@ -485,7 +484,7 @@ public class TestPlanExecuteService { boolean execError = false; try { LogUtils.info("用例类型该节点的串行执行完成! --- 队列ID[{}],队列类型[{}],开始执行下一个队列:ID[{}],类型[{}]", queueID, queueType, nextQueue.getQueueId(), nextQueue.getQueueType()); - this.executeNextNode(nextQueue); + this.executeNextNode(nextQueue, false); } catch (Exception e) { execError = true; } @@ -524,7 +523,7 @@ public class TestPlanExecuteService { boolean execError = false; try { LogUtils.info("测试计划该节点的串行执行完成! --- 队列ID[{}],队列类型[{}],开始执行下一个队列:ID[{}],类型[{}]", queueID, queueType, nextQueue.getQueueId(), nextQueue.getQueueType()); - this.executeNextNode(nextQueue); + this.executeNextNode(nextQueue, false); } catch (Exception e) { execError = true; } @@ -554,7 +553,7 @@ public class TestPlanExecuteService { boolean execError = false; try { LogUtils.info("计划组该节点的串行执行完成! --- 队列ID[{}],队列类型[{}],开始执行下一个队列:ID[{}],类型[{}]", queueID, queueType, nextQueue.getQueueId(), nextQueue.getQueueType()); - this.executeNextNode(nextQueue); + this.executeNextNode(nextQueue, false); } catch (Exception e) { execError = true; } @@ -571,7 +570,7 @@ public class TestPlanExecuteService { } } - private void executeNextNode(TestPlanExecutionQueue queue) { + private void executeNextNode(TestPlanExecutionQueue queue, boolean isStopOnFailure) { LogUtils.info("开始执行下一个节点: --- 队列ID[{}],队列类型[{}],预生成报告ID[{}]", queue.getQueueId(), queue.getQueueType(), queue.getPrepareReportId()); if (StringUtils.equalsIgnoreCase(queue.getQueueType(), QUEUE_PREFIX_TEST_PLAN_BATCH_EXECUTE)) { this.executeTestPlanOrGroup(queue); @@ -582,7 +581,21 @@ public class TestPlanExecuteService { } else if (StringUtils.equalsIgnoreCase(queue.getQueueType(), QUEUE_PREFIX_TEST_PLAN_CASE_TYPE)) { this.executeByTestPlanCollection(queue); } else if (StringUtils.equalsIgnoreCase(queue.getQueueType(), QUEUE_PREFIX_TEST_PLAN_COLLECTION)) { - this.executeCase(queue); + // 判断是否是失败停止。 如果是失败停止,要检测父类是否也同样配置了失败停止。是的话,不再执行。 + if (this.isCaseTypeExecuteStop(queue.getSourceID(), isStopOnFailure)) { + this.collectionExecuteQueueFinish(queue.getQueueId(), isStopOnFailure); + } else { + this.executeCase(queue); + } + } + } + + private boolean isCaseTypeExecuteStop(String collectionId, boolean isStopOnFailure) { + boolean caseTypeStopOnFailure = extTestPlanCollectionMapper.getParentStopOnFailure(collectionId); + if (isStopOnFailure) { + return caseTypeStopOnFailure; + } else { + return false; } } diff --git a/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanExecuteTests.java b/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanExecuteTests.java index 4f1dd8d834..b43f9970fa 100644 --- a/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanExecuteTests.java +++ b/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanExecuteTests.java @@ -304,7 +304,7 @@ public class TestPlanExecuteTests extends BaseTest { String collectionFinishQueueIds = collectionQueueIdList.getFirst(); //模拟执行完成之后的回调 - testPlanExecuteService.collectionExecuteQueueFinish(collectionFinishQueueIds); + testPlanExecuteService.collectionExecuteQueueFinish(collectionFinishQueueIds, false); allQueueIds = new ArrayList<>(); collectionQueueIdList = new ArrayList<>();