feat(测试计划): 测试计划支持不同用例之间的失败停止

This commit is contained in:
Jianguo-Genius 2024-09-29 16:36:01 +08:00 committed by Craftsman
parent 8531b2c05b
commit 994861ae7a
11 changed files with 45 additions and 25 deletions

View File

@ -35,8 +35,8 @@ public class ApiExecuteCallbackServiceInvoker {
getCallbackService(getApiExecuteResourceType(resourceType)).executeNextTask(queue, queueDetail); getCallbackService(getApiExecuteResourceType(resourceType)).executeNextTask(queue, queueDetail);
} }
public static void executeNextCollection(String resourceType, String collectionQueueId) { public static void executeNextCollection(String resourceType, String collectionQueueId, boolean isStopOnFailure) {
getCallbackService(getApiExecuteResourceType(resourceType)).executeNextCollection(collectionQueueId); getCallbackService(getApiExecuteResourceType(resourceType)).executeNextCollection(collectionQueueId, isStopOnFailure);
} }
public static void stopCollectionOnFailure(String resourceType, String collectionQueueId) { public static void stopCollectionOnFailure(String resourceType, String collectionQueueId) {

View File

@ -95,7 +95,7 @@ public class MessageListener {
} }
if (BooleanUtils.isTrue(dto.getChildCollectionExecuteOver()) || isStopOnFailure(dto)) { if (BooleanUtils.isTrue(dto.getChildCollectionExecuteOver()) || isStopOnFailure(dto)) {
// 如果当前测试集执行完了或者当前测试集失败停止了执行下一个测试集 // 如果当前测试集执行完了或者当前测试集失败停止了执行下一个测试集
ApiExecuteCallbackServiceInvoker.executeNextCollection(dto.getResourceType(), dto.getParentQueueId()); ApiExecuteCallbackServiceInvoker.executeNextCollection(dto.getResourceType(), dto.getParentQueueId(),isStopOnFailure(dto));
} }
} }

View File

@ -27,7 +27,8 @@ public interface ApiExecuteCallbackService {
* 测试集下用例执行完成时回调 * 测试集下用例执行完成时回调
* @param collectionQueueId * @param collectionQueueId
*/ */
default void executeNextCollection(String collectionQueueId) {} default void executeNextCollection(String collectionQueueId, boolean isStopOnFailure) {
}
/** /**
* 失败停止时处理 parentQueue * 失败停止时处理 parentQueue

View File

@ -15,4 +15,6 @@ public interface ExtTestPlanCollectionMapper {
TestPlanCollectionEnvDTO selectFirstCollectionEnv(@Param("type") String type, @Param("parentId") String parentId, @Param("testPlanId") String testPlanId); TestPlanCollectionEnvDTO selectFirstCollectionEnv(@Param("type") String type, @Param("parentId") String parentId, @Param("testPlanId") String testPlanId);
String selectDefaultCollectionId(@Param("testPlanId")String newTestPlanId,@Param("type") String key); String selectDefaultCollectionId(@Param("testPlanId")String newTestPlanId,@Param("type") String key);
boolean getParentStopOnFailure(String collectionId);
} }

View File

@ -59,4 +59,9 @@
ORDER BY pos ORDER BY pos
limit 1 limit 1
</select> </select>
<select id="getParentStopOnFailure" resultType="java.lang.Boolean">
select stop_on_fail
from test_plan_collection
where id IN (select parent_id from test_plan_collection where id = #{0})
</select>
</mapper> </mapper>

View File

@ -52,7 +52,7 @@ public class PlanRunApiCaseExecuteCallbackService implements ApiExecuteCallbackS
* @param parentQueueId * @param parentQueueId
*/ */
@Override @Override
public void executeNextCollection(String parentQueueId) { public void executeNextCollection(String parentQueueId, boolean isStopOnFailure) {
testPlanExecuteService.collectionExecuteQueueFinish(parentQueueId); testPlanExecuteService.collectionExecuteQueueFinish(parentQueueId, isStopOnFailure);
} }
} }

View File

@ -52,7 +52,7 @@ public class PlanRunApiScenarioExecuteCallbackService implements ApiExecuteCallb
* @param parentQueueId * @param parentQueueId
*/ */
@Override @Override
public void executeNextCollection(String parentQueueId) { public void executeNextCollection(String parentQueueId, boolean isStopOnFailure) {
testPlanExecuteService.collectionExecuteQueueFinish(parentQueueId); testPlanExecuteService.collectionExecuteQueueFinish(parentQueueId, isStopOnFailure);
} }
} }

View File

@ -48,10 +48,9 @@ public class TestPlanApiCaseExecuteCallbackService implements ApiExecuteCallback
/** /**
* 批量串行的测试集执行时 * 批量串行的测试集执行时
* 测试集下用例执行完成时回调 * 测试集下用例执行完成时回调
* @param parentQueueId
*/ */
@Override @Override
public void executeNextCollection(String parentQueueId) { public void executeNextCollection(String parentQueueId, boolean isStopOnFailure) {
testPlanApiCaseBatchRunService.executeNextCollection(parentQueueId); testPlanApiCaseBatchRunService.executeNextCollection(parentQueueId);
} }

View File

@ -51,7 +51,7 @@ public class TestPlanApiScenarioExecuteCallbackService implements ApiExecuteCall
* @param collectionQueueId * @param collectionQueueId
*/ */
@Override @Override
public void executeNextCollection(String collectionQueueId) { public void executeNextCollection(String collectionQueueId, boolean isStopOnFailure) {
testPlanApiScenarioBatchRunService.executeNextCollection(collectionQueueId); testPlanApiScenarioBatchRunService.executeNextCollection(collectionQueueId);
} }

View File

@ -5,10 +5,7 @@ import io.metersphere.plan.domain.*;
import io.metersphere.plan.dto.request.TestPlanBatchExecuteRequest; import io.metersphere.plan.dto.request.TestPlanBatchExecuteRequest;
import io.metersphere.plan.dto.request.TestPlanExecuteRequest; import io.metersphere.plan.dto.request.TestPlanExecuteRequest;
import io.metersphere.plan.dto.request.TestPlanReportGenRequest; import io.metersphere.plan.dto.request.TestPlanReportGenRequest;
import io.metersphere.plan.mapper.TestPlanCollectionMapper; import io.metersphere.plan.mapper.*;
import io.metersphere.plan.mapper.TestPlanConfigMapper;
import io.metersphere.plan.mapper.TestPlanMapper;
import io.metersphere.plan.mapper.TestPlanReportMapper;
import io.metersphere.sdk.constants.*; import io.metersphere.sdk.constants.*;
import io.metersphere.sdk.dto.queue.TestPlanExecutionQueue; import io.metersphere.sdk.dto.queue.TestPlanExecutionQueue;
import io.metersphere.sdk.exception.MSException; import io.metersphere.sdk.exception.MSException;
@ -35,6 +32,8 @@ public class TestPlanExecuteService {
@Resource @Resource
private TestPlanMapper testPlanMapper; private TestPlanMapper testPlanMapper;
@Resource @Resource
private ExtTestPlanCollectionMapper extTestPlanCollectionMapper;
@Resource
private TestPlanConfigMapper testPlanConfigMapper; private TestPlanConfigMapper testPlanConfigMapper;
@Resource @Resource
private TestPlanService testPlanService; private TestPlanService testPlanService;
@ -424,7 +423,7 @@ public class TestPlanExecuteService {
if (execOver) { 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); LogUtils.info("收到测试集执行完成的信息: [{}]", paramQueueId);
String queueID = paramQueueId; String queueID = paramQueueId;
String[] queueIdArr = queueID.split("_"); String[] queueIdArr = queueID.split("_");
@ -454,13 +453,13 @@ public class TestPlanExecuteService {
boolean execError = false; boolean execError = false;
try { try {
LogUtils.info("测试集该节点的串行执行完成! --- 队列ID[{}],队列类型[{}]开始执行下一个队列ID[{}],类型[{}]", queueID, queueType, nextQueue.getQueueId(), nextQueue.getQueueType()); LogUtils.info("测试集该节点的串行执行完成! --- 队列ID[{}],队列类型[{}]开始执行下一个队列ID[{}],类型[{}]", queueID, queueType, nextQueue.getQueueId(), nextQueue.getQueueType());
this.executeNextNode(nextQueue); this.executeNextNode(nextQueue, isStopOnFailure);
} catch (Exception e) { } catch (Exception e) {
Log.error("测试集下一个节点执行失败!", e); Log.error("测试集下一个节点执行失败!", e);
execError = true; execError = true;
} }
if (execError) { if (execError) {
this.collectionExecuteQueueFinish(nextQueue.getQueueId()); this.collectionExecuteQueueFinish(nextQueue.getQueueId(), true);
} }
} else { } else {
//当前测试集执行完毕 //当前测试集执行完毕
@ -485,7 +484,7 @@ public class TestPlanExecuteService {
boolean execError = false; boolean execError = false;
try { try {
LogUtils.info("用例类型该节点的串行执行完成! --- 队列ID[{}],队列类型[{}]开始执行下一个队列ID[{}],类型[{}]", queueID, queueType, nextQueue.getQueueId(), nextQueue.getQueueType()); LogUtils.info("用例类型该节点的串行执行完成! --- 队列ID[{}],队列类型[{}]开始执行下一个队列ID[{}],类型[{}]", queueID, queueType, nextQueue.getQueueId(), nextQueue.getQueueType());
this.executeNextNode(nextQueue); this.executeNextNode(nextQueue, false);
} catch (Exception e) { } catch (Exception e) {
execError = true; execError = true;
} }
@ -524,7 +523,7 @@ public class TestPlanExecuteService {
boolean execError = false; boolean execError = false;
try { try {
LogUtils.info("测试计划该节点的串行执行完成! --- 队列ID[{}],队列类型[{}]开始执行下一个队列ID[{}],类型[{}]", queueID, queueType, nextQueue.getQueueId(), nextQueue.getQueueType()); LogUtils.info("测试计划该节点的串行执行完成! --- 队列ID[{}],队列类型[{}]开始执行下一个队列ID[{}],类型[{}]", queueID, queueType, nextQueue.getQueueId(), nextQueue.getQueueType());
this.executeNextNode(nextQueue); this.executeNextNode(nextQueue, false);
} catch (Exception e) { } catch (Exception e) {
execError = true; execError = true;
} }
@ -554,7 +553,7 @@ public class TestPlanExecuteService {
boolean execError = false; boolean execError = false;
try { try {
LogUtils.info("计划组该节点的串行执行完成! --- 队列ID[{}],队列类型[{}]开始执行下一个队列ID[{}],类型[{}]", queueID, queueType, nextQueue.getQueueId(), nextQueue.getQueueType()); LogUtils.info("计划组该节点的串行执行完成! --- 队列ID[{}],队列类型[{}]开始执行下一个队列ID[{}],类型[{}]", queueID, queueType, nextQueue.getQueueId(), nextQueue.getQueueType());
this.executeNextNode(nextQueue); this.executeNextNode(nextQueue, false);
} catch (Exception e) { } catch (Exception e) {
execError = true; 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()); LogUtils.info("开始执行下一个节点: --- 队列ID[{}],队列类型[{}]预生成报告ID[{}]", queue.getQueueId(), queue.getQueueType(), queue.getPrepareReportId());
if (StringUtils.equalsIgnoreCase(queue.getQueueType(), QUEUE_PREFIX_TEST_PLAN_BATCH_EXECUTE)) { if (StringUtils.equalsIgnoreCase(queue.getQueueType(), QUEUE_PREFIX_TEST_PLAN_BATCH_EXECUTE)) {
this.executeTestPlanOrGroup(queue); this.executeTestPlanOrGroup(queue);
@ -582,9 +581,23 @@ public class TestPlanExecuteService {
} else if (StringUtils.equalsIgnoreCase(queue.getQueueType(), QUEUE_PREFIX_TEST_PLAN_CASE_TYPE)) { } else if (StringUtils.equalsIgnoreCase(queue.getQueueType(), QUEUE_PREFIX_TEST_PLAN_CASE_TYPE)) {
this.executeByTestPlanCollection(queue); this.executeByTestPlanCollection(queue);
} else if (StringUtils.equalsIgnoreCase(queue.getQueueType(), QUEUE_PREFIX_TEST_PLAN_COLLECTION)) { } else if (StringUtils.equalsIgnoreCase(queue.getQueueType(), QUEUE_PREFIX_TEST_PLAN_COLLECTION)) {
// 判断是否是失败停止 如果是失败停止要检测父类是否也同样配置了失败停止是的话不再执行
if (this.isCaseTypeExecuteStop(queue.getSourceID(), isStopOnFailure)) {
this.collectionExecuteQueueFinish(queue.getQueueId(), isStopOnFailure);
} else {
this.executeCase(queue); this.executeCase(queue);
} }
} }
}
private boolean isCaseTypeExecuteStop(String collectionId, boolean isStopOnFailure) {
boolean caseTypeStopOnFailure = extTestPlanCollectionMapper.getParentStopOnFailure(collectionId);
if (isStopOnFailure) {
return caseTypeStopOnFailure;
} else {
return false;
}
}
private void queueExecuteFinish(TestPlanExecutionQueue queue) { private void queueExecuteFinish(TestPlanExecutionQueue queue) {
LogUtils.info("当前节点执行完成: --- 队列ID[{}],队列类型[{}]父队列ID[{}],父队列类型[{}]", queue.getQueueId(), queue.getQueueType(), queue.getParentQueueId(), queue.getParentQueueType()); LogUtils.info("当前节点执行完成: --- 队列ID[{}],队列类型[{}]父队列ID[{}],父队列类型[{}]", queue.getQueueId(), queue.getQueueType(), queue.getParentQueueId(), queue.getParentQueueType());

View File

@ -304,7 +304,7 @@ public class TestPlanExecuteTests extends BaseTest {
String collectionFinishQueueIds = collectionQueueIdList.getFirst(); String collectionFinishQueueIds = collectionQueueIdList.getFirst();
//模拟执行完成之后的回调 //模拟执行完成之后的回调
testPlanExecuteService.collectionExecuteQueueFinish(collectionFinishQueueIds); testPlanExecuteService.collectionExecuteQueueFinish(collectionFinishQueueIds, false);
allQueueIds = new ArrayList<>(); allQueueIds = new ArrayList<>();
collectionQueueIdList = new ArrayList<>(); collectionQueueIdList = new ArrayList<>();