fix(测试计划): 修复测试计划多个测试集并行时可能会出现执行完无法进行回调的问题

This commit is contained in:
Jianguo-Genius 2024-06-24 21:22:00 +08:00 committed by 刘瑞斌
parent 75f0d83ac8
commit 98a9fc662b
3 changed files with 17 additions and 6 deletions

View File

@ -28,6 +28,7 @@ import io.metersphere.sdk.dto.queue.TestPlanExecutionQueue;
import io.metersphere.sdk.util.JSON; import io.metersphere.sdk.util.JSON;
import io.metersphere.sdk.util.LogUtils; import io.metersphere.sdk.util.LogUtils;
import io.metersphere.sdk.util.SubListUtils; import io.metersphere.sdk.util.SubListUtils;
import io.metersphere.system.uid.IDGenerator;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import jodd.util.StringUtil; import jodd.util.StringUtil;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
@ -106,7 +107,7 @@ public class PlanRunTestPlanApiCaseService {
* @return 是否执行完毕 * @return 是否执行完毕
*/ */
public boolean parallelExecute(TestPlanExecutionQueue testPlanExecutionQueue) { public boolean parallelExecute(TestPlanExecutionQueue testPlanExecutionQueue) {
String parentQueueId = testPlanExecutionQueue.getQueueId(); String parentQueueId = testPlanExecutionQueue.getQueueId() + "_" + IDGenerator.nextStr();
String testPlanReportId = testPlanExecutionQueue.getPrepareReportId(); String testPlanReportId = testPlanExecutionQueue.getPrepareReportId();
String userId = testPlanExecutionQueue.getCreateUser(); String userId = testPlanExecutionQueue.getCreateUser();
TestPlanCollection collection = JSON.parseObject(testPlanExecutionQueue.getTestPlanCollectionJson(), TestPlanCollection.class); TestPlanCollection collection = JSON.parseObject(testPlanExecutionQueue.getTestPlanCollectionJson(), TestPlanCollection.class);

View File

@ -27,6 +27,7 @@ import io.metersphere.sdk.dto.queue.TestPlanExecutionQueue;
import io.metersphere.sdk.util.JSON; import io.metersphere.sdk.util.JSON;
import io.metersphere.sdk.util.LogUtils; import io.metersphere.sdk.util.LogUtils;
import io.metersphere.sdk.util.SubListUtils; import io.metersphere.sdk.util.SubListUtils;
import io.metersphere.system.uid.IDGenerator;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -100,7 +101,7 @@ public class PlanRunTestPlanApiScenarioService {
* @return 是否执行完毕 * @return 是否执行完毕
*/ */
public boolean parallelExecute(TestPlanExecutionQueue testPlanExecutionQueue) { public boolean parallelExecute(TestPlanExecutionQueue testPlanExecutionQueue) {
String parentQueueId = testPlanExecutionQueue.getQueueId(); String parentQueueId = testPlanExecutionQueue.getQueueId() + "_" + IDGenerator.nextStr();
String testPlanReportId = testPlanExecutionQueue.getPrepareReportId(); String testPlanReportId = testPlanExecutionQueue.getPrepareReportId();
String userId = testPlanExecutionQueue.getCreateUser(); String userId = testPlanExecutionQueue.getCreateUser();
TestPlanCollection collection = JSON.parseObject(testPlanExecutionQueue.getTestPlanCollectionJson(), TestPlanCollection.class); TestPlanCollection collection = JSON.parseObject(testPlanExecutionQueue.getTestPlanCollectionJson(), TestPlanCollection.class);

View File

@ -365,7 +365,7 @@ public class TestPlanExecuteService {
}} }}
); );
} }
LogUtils.info("测试计划不同用例类型的执行节点 --- 队列ID[{}],队列类型[{}],父队列ID[{}],父队列类型[{}],执行模式[{}]", queueId, queueType, executionQueue.getParentQueueId(), executionQueue.getParentQueueType(), executionQueue.getRunMode()); LogUtils.info("测试计划不同用例类型的执行节点 --- 队列ID[{}],队列类型[{}],父队列ID[{}],父队列类型[{}],执行模式[{}]", executionQueue.getQueueId(), executionQueue.getQueueType(), executionQueue.getParentQueueId(), executionQueue.getParentQueueType(), executionQueue.getRunMode());
if (CollectionUtils.isEmpty(childrenQueue)) { if (CollectionUtils.isEmpty(childrenQueue)) {
//本次的测试集执行完成 //本次的测试集执行完成
this.caseTypeExecuteQueueFinish(executionQueue.getQueueId(), executionQueue.getQueueType()); this.caseTypeExecuteQueueFinish(executionQueue.getQueueId(), executionQueue.getQueueType());
@ -393,7 +393,9 @@ public class TestPlanExecuteService {
*/ */
private void executeCase(TestPlanExecutionQueue testPlanExecutionQueue) { private void executeCase(TestPlanExecutionQueue testPlanExecutionQueue) {
String queueId = testPlanExecutionQueue.getQueueId(); String queueId = testPlanExecutionQueue.getQueueId();
LogUtils.info("测试集执行节点 --- 队列ID[{}],队列类型[{}],父队列ID[{}],父队列类型[{}],执行模式[{}]", queueId, testPlanExecutionQueue.getQueueType(), testPlanExecutionQueue.getParentQueueId(), testPlanExecutionQueue.getParentQueueType(), testPlanExecutionQueue.getRunMode()); LogUtils.info("测试集执行节点 --- 队列ID[{}],队列类型[{}],父队列ID[{}],父队列类型[{}],执行模式[{},资源ID[{}]",
queueId, testPlanExecutionQueue.getQueueType(), testPlanExecutionQueue.getParentQueueId(), testPlanExecutionQueue.getParentQueueType(),
testPlanExecutionQueue.getRunMode(), testPlanExecutionQueue.getSourceID());
boolean execOver = false; boolean execOver = false;
try { try {
TestPlanCollection collection = JSON.parseObject(testPlanExecutionQueue.getTestPlanCollectionJson(), TestPlanCollection.class); TestPlanCollection collection = JSON.parseObject(testPlanExecutionQueue.getTestPlanCollectionJson(), TestPlanCollection.class);
@ -428,10 +430,17 @@ public class TestPlanExecuteService {
} }
//测试集执行完成 //测试集执行完成
public void collectionExecuteQueueFinish(String queueID) { public void collectionExecuteQueueFinish(String paramQueueId) {
LogUtils.info("收到测试集执行完成的信息: [{}]", paramQueueId);
String queueID = paramQueueId;
String[] queueIdArr = queueID.split("_");
if (queueIdArr.length > 2) {
queueID = queueIdArr[0] + "_" + queueIdArr[1];
}
String queueType = QUEUE_PREFIX_TEST_PLAN_COLLECTION; String queueType = QUEUE_PREFIX_TEST_PLAN_COLLECTION;
LogUtils.info("收到测试集执行完成的信息: 队列ID[{}],队列类型[{}],下一个节点的执行工作准备中...", queueID, queueType);
TestPlanExecutionQueue nextQueue = testPlanExecuteSupportService.getNextQueue(queueID, queueType); TestPlanExecutionQueue nextQueue = testPlanExecuteSupportService.getNextQueue(queueID, queueType);
LogUtils.info("获取执行节点完成: 队列ID[{}],队列类型[{},串并行:[{}]执行是否结束[{}],是否是最后一个[{}],当前查出节点的资源ID[{}]],下一个节点的执行工作准备中...",
queueID, queueType, nextQueue.getRunMode(), nextQueue.isExecuteFinish(), nextQueue.isLastOne(), nextQueue.getSourceID());
if (StringUtils.equalsIgnoreCase(nextQueue.getRunMode(), ApiBatchRunMode.SERIAL.name())) { if (StringUtils.equalsIgnoreCase(nextQueue.getRunMode(), ApiBatchRunMode.SERIAL.name())) {
//串行时由于是先拿出节点再判断执行所以要判断节点的isExecuteFinish //串行时由于是先拿出节点再判断执行所以要判断节点的isExecuteFinish
if (!nextQueue.isExecuteFinish()) { if (!nextQueue.isExecuteFinish()) {