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);
}
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) {

View File

@ -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));
}
}

View File

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

View File

@ -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);
}

View File

@ -59,4 +59,9 @@
ORDER BY pos
limit 1
</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>

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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;
}
}

View File

@ -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<>();