refactor(测试计划): 停止测试计划

This commit is contained in:
wxg0103 2024-06-17 20:17:52 +08:00 committed by Craftsman
parent 813de4894c
commit 3d1a66ba59
6 changed files with 21 additions and 18 deletions

View File

@ -205,13 +205,13 @@
asr.test_plan_scenario_id AS resourceId
FROM
api_scenario_report asr
LEFT JOIN test_plan_report_api_scenario tpras ON asr.id = tpras.test_plan_report_id
LEFT JOIN test_plan_report_api_scenario tpras ON asr.id = tpras.api_scenario_execute_report_id
LEFT JOIN project ON asr.project_id = project.id
WHERE
asr.deleted = FALSE
AND asr.plan = 1
AND asr.exec_status IN ( 'PENDING', 'RUNNING', 'RERUNNING' )
AND tpras.api_scenario_execute_report_id IN
AND tpras.test_plan_report_id IN
<foreach collection="ids" item="id" open="(" close=")" separator=",">
#{id}
</foreach>

View File

@ -12,7 +12,10 @@ import io.metersphere.api.service.queue.ApiExecutionQueueService;
import io.metersphere.api.service.queue.ApiExecutionSetService;
import io.metersphere.api.service.scenario.ApiScenarioReportService;
import io.metersphere.api.service.scenario.ApiScenarioRunService;
import io.metersphere.plan.domain.*;
import io.metersphere.plan.domain.TestPlan;
import io.metersphere.plan.domain.TestPlanCollection;
import io.metersphere.plan.domain.TestPlanReportApiScenario;
import io.metersphere.plan.domain.TestPlanReportApiScenarioExample;
import io.metersphere.plan.mapper.ExtTestPlanApiScenarioMapper;
import io.metersphere.plan.mapper.TestPlanMapper;
import io.metersphere.plan.mapper.TestPlanReportApiScenarioMapper;
@ -24,7 +27,6 @@ import io.metersphere.sdk.dto.queue.TestPlanExecutionQueue;
import io.metersphere.sdk.util.JSON;
import io.metersphere.sdk.util.LogUtils;
import io.metersphere.sdk.util.SubListUtils;
import io.metersphere.system.uid.IDGenerator;
import jakarta.annotation.Resource;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Service;
@ -66,6 +68,7 @@ public class PlanRunTestPlanApiScenarioService {
/**
* 串行批量执行
*
* @Return 是否执行完毕
*/
public boolean serialExecute(TestPlanExecutionQueue testPlanExecutionQueue) {
@ -91,6 +94,7 @@ public class PlanRunTestPlanApiScenarioService {
/**
* 并行批量执行
*
* @return 是否执行完毕
*/
public boolean parallelExecute(TestPlanExecutionQueue testPlanExecutionQueue) {
@ -158,7 +162,6 @@ public class PlanRunTestPlanApiScenarioService {
apiScenarioReport.setEnvironmentId(apiBatchRunBaseService.getEnvId(runModeConfig, testPlanReportApiScenario.getEnvironmentId()));
apiScenarioReport.setPlan(true);
apiScenarioReport.setId(IDGenerator.nextStr());
apiScenarioReports.add(apiScenarioReport);
// 创建报告和用例的关联关系
ApiScenarioRecord scenarioRecord = new ApiScenarioRecord();

View File

@ -94,9 +94,9 @@ public class TestPlanExecuteService {
testPlanItemReport.forEach(item -> {
this.deepDeleteTestPlanCaseType(item);
//统计子测试计划报告
summaryTestPlanReport(item.getId(), false);
summaryTestPlanReport(item.getId(), false, true);
});
summaryTestPlanReport(testPlanReportId, true);
summaryTestPlanReport(testPlanReportId, true, true);
this.testPlanExecuteQueueFinish(nextTestPlanQueue.getParentQueueId(), nextTestPlanQueue.getParentQueueType());
} else {
/*
@ -114,7 +114,7 @@ public class TestPlanExecuteService {
return;
}
this.deepDeleteTestPlanCaseType(testPlanReport);
summaryTestPlanReport(testPlanReportId, false);
summaryTestPlanReport(testPlanReportId, false, true);
this.testPlanExecuteQueueFinish(nextTestPlanQueue.getParentQueueId(), nextTestPlanQueue.getParentQueueType());
}
@ -140,7 +140,7 @@ public class TestPlanExecuteService {
public String singleExecuteTestPlan(TestPlanExecuteRequest request, String userId) {
TestPlanExecutionQueue executionQueue = new TestPlanExecutionQueue();
executionQueue.setSourceID(request.getExecuteId());
executionQueue.setRunMode(request.getRunMode());
executionQueue.setRunMode(ApiBatchRunMode.PARALLEL.name());
executionQueue.setExecutionSource(request.getExecutionSource());
executionQueue.setQueueId(IDGenerator.nextStr());
executionQueue.setQueueType(QUEUE_PREFIX_TEST_PLAN_BATCH_EXECUTE);
@ -156,7 +156,7 @@ public class TestPlanExecuteService {
null,
null,
request.getExecuteId(),
request.getRunMode(),
executionQueue.getRunMode(),
executionQueue.getExecutionSource(),
IDGenerator.nextStr()
);
@ -558,7 +558,7 @@ public class TestPlanExecuteService {
}
}
private void summaryTestPlanReport(String reportId, boolean isGroupReport) {
private void summaryTestPlanReport(String reportId, boolean isGroupReport, boolean isStop) {
LogUtils.info("开始合并报告: --- 报告ID[{}],是否是报告组[{}]", reportId, isGroupReport);
try {
if (isGroupReport) {
@ -571,7 +571,7 @@ public class TestPlanExecuteService {
postParam.setReportId(reportId);
// 执行生成报告, 执行状态为已完成, 执行及结束时间为当前时间
postParam.setEndTime(System.currentTimeMillis());
postParam.setExecStatus(ExecStatus.COMPLETED.name());
postParam.setExecStatus(isStop ? ExecStatus.STOPPED.name() : ExecStatus.COMPLETED.name());
testPlanReportService.postHandleReport(postParam, false);
if (!isGroupReport) {
@ -590,19 +590,19 @@ public class TestPlanExecuteService {
if (StringUtils.equalsIgnoreCase(queue.getParentQueueType(), QUEUE_PREFIX_TEST_PLAN_BATCH_EXECUTE)) {
if (StringUtils.equalsIgnoreCase(queue.getQueueType(), QUEUE_PREFIX_TEST_PLAN_GROUP_EXECUTE)) {
// 计划组报告汇总并统计
this.summaryTestPlanReport(queue.getQueueId(), true);
this.summaryTestPlanReport(queue.getQueueId(), true, false);
} else if (StringUtils.equalsIgnoreCase(queue.getQueueType(), QUEUE_PREFIX_TEST_PLAN_CASE_TYPE)) {
/*
此时处于批量勾选执行中的游离态测试计划执行所以队列顺序为QUEUE_PREFIX_TEST_PLAN_BATCH_EXECUTE -> QUEUE_PREFIX_TEST_PLAN_CASE_TYPE
此时queue节点为testPlanCollection的节点 而测试计划节点串行状态下在执行之前就被弹出了
所以获取报告ID的方式为读取queueId caseType队列和collection队列的queueId都是报告ID
*/
this.summaryTestPlanReport(queue.getQueueId(), false);
this.summaryTestPlanReport(queue.getQueueId(), false, false);
}
this.testPlanGroupQueueFinish(queue.getParentQueueId(), queue.getParentQueueType());
} else if (StringUtils.equalsIgnoreCase(queue.getParentQueueType(), QUEUE_PREFIX_TEST_PLAN_GROUP_EXECUTE)) {
// 计划报告汇总并统计
this.summaryTestPlanReport(queue.getQueueId(), false);
this.summaryTestPlanReport(queue.getQueueId(), false, false);
this.testPlanExecuteQueueFinish(queue.getParentQueueId(), queue.getParentQueueType());
} else if (StringUtils.equalsIgnoreCase(queue.getParentQueueType(), QUEUE_PREFIX_TEST_PLAN_CASE_TYPE)) {
this.caseTypeExecuteQueueFinish(queue.getParentQueueId(), queue.getParentQueueType());

View File

@ -479,7 +479,7 @@
function stop(record: any) {
openModal({
type: 'warning',
title: t('project.taskCenter.stopTask', { name: characterLimit(record.name) }),
title: t('project.taskCenter.stopTask', { name: characterLimit(record.resourceName) }),
content: t('project.taskCenter.stopTaskContent'),
okText: t('project.taskCenter.confirmStop'),
cancelText: t('common.cancel'),

View File

@ -436,7 +436,7 @@
function stop(record: any) {
openModal({
type: 'warning',
title: t('project.taskCenter.stopTask', { name: characterLimit(record.name) }),
title: t('project.taskCenter.stopTask', { name: characterLimit(record.resourceName) }),
content: t('project.taskCenter.stopTaskContent'),
okText: t('project.taskCenter.confirmStop'),
cancelText: t('common.cancel'),

View File

@ -18,7 +18,7 @@ export default {
'project.taskCenter.execution': '执行',
'project.taskCenter.viewReport': '执行结果',
'project.taskCenter.batchStopTask': '确定停止 {num} 个任务吗?',
'project.taskCenter.stopTask': '确定停止 {name} 个任务吗?',
'project.taskCenter.stopTask': '确定停止 {name} 吗?',
'project.taskCenter.stopTaskContent': '停止后会影响报告的生成,执行完成的报告不可以停止',
'project.taskCenter.confirmStop': '确认停止',
'project.taskCenter.stopSuccess': '停止成功',