fix(接口测试): 超时报告处理

This commit is contained in:
fit2-zhao 2021-12-21 14:51:32 +08:00 committed by 刘瑞斌
parent 19a61665de
commit 94f610181d
3 changed files with 17 additions and 16 deletions

View File

@ -26,9 +26,9 @@ public class TestPlanReportListenerScheduled {
} }
private void listener(String planReportId) { private void listener(String planReportId) {
LoggerUtil.info("检查测试计划执行报告:【" + planReportId + "");
if (TestPlanReportExecuteCatch.getTestPlanExecuteInfo(planReportId) != null) { if (TestPlanReportExecuteCatch.getTestPlanExecuteInfo(planReportId) != null) {
if (!CommonBeanFactory.getBean(ExecThreadPoolExecutor.class).checkPlanReport(planReportId)) { if (!CommonBeanFactory.getBean(ExecThreadPoolExecutor.class).checkPlanReport(planReportId)) {
LoggerUtil.info("检查测试计划执行报告:【" + planReportId + "");
CommonBeanFactory.getBean(TestPlanReportService.class).countReport(planReportId); CommonBeanFactory.getBean(TestPlanReportService.class).countReport(planReportId);
} }
} else { } else {

View File

@ -11,6 +11,7 @@ import io.metersphere.base.mapper.ApiExecutionQueueMapper;
import io.metersphere.base.mapper.ApiScenarioReportMapper; import io.metersphere.base.mapper.ApiScenarioReportMapper;
import io.metersphere.base.mapper.ext.ExtApiExecutionQueueMapper; import io.metersphere.base.mapper.ext.ExtApiExecutionQueueMapper;
import io.metersphere.commons.constants.ApiRunMode; import io.metersphere.commons.constants.ApiRunMode;
import io.metersphere.commons.constants.TestPlanReportStatus;
import io.metersphere.commons.utils.BeanUtils; import io.metersphere.commons.utils.BeanUtils;
import io.metersphere.constants.RunModeConstants; import io.metersphere.constants.RunModeConstants;
import io.metersphere.dto.ResultDTO; import io.metersphere.dto.ResultDTO;
@ -179,8 +180,8 @@ public class ApiExecutionQueueService {
final int SECOND_MILLIS = 1000; final int SECOND_MILLIS = 1000;
final int MINUTE_MILLIS = 60 * SECOND_MILLIS; final int MINUTE_MILLIS = 60 * SECOND_MILLIS;
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
// 分钟前的数据 // 分钟前的数据
now = now - 5 * MINUTE_MILLIS; now = now - 8 * MINUTE_MILLIS;
ApiExecutionQueueDetailExample example = new ApiExecutionQueueDetailExample(); ApiExecutionQueueDetailExample example = new ApiExecutionQueueDetailExample();
example.createCriteria().andCreateTimeLessThan(now); example.createCriteria().andCreateTimeLessThan(now);
List<ApiExecutionQueueDetail> queueDetails = executionQueueDetailMapper.selectByExample(example); List<ApiExecutionQueueDetail> queueDetails = executionQueueDetailMapper.selectByExample(example);
@ -189,13 +190,13 @@ public class ApiExecutionQueueService {
queueDetails.forEach(item -> { queueDetails.forEach(item -> {
if (StringUtils.equalsAny(item.getType(), ApiRunMode.SCENARIO.name(), ApiRunMode.SCENARIO_PLAN.name(), ApiRunMode.SCHEDULE_SCENARIO_PLAN.name(), ApiRunMode.SCHEDULE_SCENARIO.name(), ApiRunMode.JENKINS_SCENARIO_PLAN.name())) { if (StringUtils.equalsAny(item.getType(), ApiRunMode.SCENARIO.name(), ApiRunMode.SCENARIO_PLAN.name(), ApiRunMode.SCHEDULE_SCENARIO_PLAN.name(), ApiRunMode.SCHEDULE_SCENARIO.name(), ApiRunMode.JENKINS_SCENARIO_PLAN.name())) {
ApiScenarioReport report = apiScenarioReportMapper.selectByPrimaryKey(item.getReportId()); ApiScenarioReport report = apiScenarioReportMapper.selectByPrimaryKey(item.getReportId());
if (report != null) { if (report != null && StringUtils.equalsAny(report.getStatus(), TestPlanReportStatus.RUNNING.name())) {
report.setStatus("timeout"); report.setStatus("timeout");
apiScenarioReportMapper.updateByPrimaryKeySelective(report); apiScenarioReportMapper.updateByPrimaryKeySelective(report);
} }
} else { } else {
ApiDefinitionExecResult result = apiDefinitionExecResultMapper.selectByPrimaryKey(item.getReportId()); ApiDefinitionExecResult result = apiDefinitionExecResultMapper.selectByPrimaryKey(item.getReportId());
if (result != null) { if (result != null && StringUtils.equalsAny(result.getStatus(), TestPlanReportStatus.RUNNING.name())) {
result.setStatus("timeout"); result.setStatus("timeout");
apiDefinitionExecResultMapper.updateByPrimaryKeySelective(result); apiDefinitionExecResultMapper.updateByPrimaryKeySelective(result);
} }
@ -210,7 +211,7 @@ public class ApiExecutionQueueService {
if (CollectionUtils.isNotEmpty(executionQueues)) { if (CollectionUtils.isNotEmpty(executionQueues)) {
executionQueues.forEach(item -> { executionQueues.forEach(item -> {
ApiScenarioReport report = apiScenarioReportMapper.selectByPrimaryKey(item.getReportId()); ApiScenarioReport report = apiScenarioReportMapper.selectByPrimaryKey(item.getReportId());
if (report != null) { if (report != null && StringUtils.equalsAny(report.getStatus(), TestPlanReportStatus.RUNNING.name())) {
report.setStatus("timeout"); report.setStatus("timeout");
apiScenarioReportMapper.updateByPrimaryKeySelective(report); apiScenarioReportMapper.updateByPrimaryKeySelective(report);
} }

View File

@ -67,27 +67,27 @@ VALUES (UUID(), 'project_app_manager', 'PROJECT_APP_MANAGER:READ+EDIT', 'PROJECT
CREATE TABLE IF NOT EXISTS `api_execution_queue` CREATE TABLE IF NOT EXISTS `api_execution_queue`
( (
`id` varchar(50) NOT NULL COMMENT 'ID', `id` varchar(50) NOT NULL COMMENT 'ID',
`test_queue` LONGTEXT COMMENT '执行资源Id队列fifo',
`report_id` varchar(100) COMMENT '集合报告/测试计划报告', `report_id` varchar(100) COMMENT '集合报告/测试计划报告',
`report_type` varchar(100) COMMENT '报告类型/计划报告/单独报告', `report_type` varchar(100) COMMENT '报告类型/计划报告/单独报告',
`run_mode` varchar(100) COMMENT '执行模式/scenario/api/test_paln_api/test_pan_scenario', `run_mode` varchar(100) COMMENT '执行模式/scenario/api/test_paln_api/test_pan_scenario',
`pool_id` varchar(100) DEFAULT NULL COMMENT '执行资源池', `pool_id` varchar(100) DEFAULT NULL COMMENT '执行资源池',
create_time bigint(13) NULL COMMENT '创建时间', create_time bigint(13) NULL COMMENT '创建时间',
PRIMARY KEY (`id`) PRIMARY KEY (`id`)
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_general_ci; ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_general_ci;
CREATE TABLE IF NOT EXISTS `api_execution_queue_detail` CREATE TABLE IF NOT EXISTS `api_execution_queue_detail`
( (
`id` varchar(50) NOT NULL COMMENT 'ID', `id` varchar(50) NOT NULL COMMENT 'ID',
`queue_id` LONGTEXT COMMENT '队列id', `queue_id` varchar(100) COMMENT '队列id',
`report_id` varchar(100) COMMENT '报告id', `sort` int COMMENT '排序',
`test_id` varchar(100) COMMENT '资源id', `report_id` varchar(100) COMMENT '报告id',
`evn_map` varchar(100) COMMENT '环境', `test_id` varchar(100) COMMENT '资源id',
`type` varchar(100) DEFAULT NULL COMMENT '资源类型', `evn_map` LONGTEXT COMMENT '环境',
`type` varchar(100) DEFAULT NULL COMMENT '资源类型',
create_time bigint(13) NULL COMMENT '创建时间', create_time bigint(13) NULL COMMENT '创建时间',
PRIMARY KEY (`id`) PRIMARY KEY (`id`)
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_general_ci; ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_general_ci;
ALTER TABLE load_test ALTER TABLE load_test
MODIFY name VARCHAR(255) NOT NULL COMMENT 'Test name'; MODIFY name VARCHAR(255) NOT NULL COMMENT 'Test name';