fix(测试计划): 修复并行或串行测试计划报告状态未结束问题
This commit is contained in:
parent
3706c8181c
commit
5d277e588a
|
@ -38,6 +38,7 @@ public class ApiCaseParallelExecuteService {
|
|||
}
|
||||
JmeterRunRequestDTO runRequest = new JmeterRunRequestDTO(testId, reportId, runMode, hashTree);
|
||||
runRequest.setPool(GenerateHashTreeUtil.isResourcePool(config.getResourcePoolId()));
|
||||
runRequest.setTestPlanReportId(executionQueue.getReportId());
|
||||
runRequest.setPoolId(config.getResourcePoolId());
|
||||
runRequest.setReportType(executionQueue.getReportType());
|
||||
runRequest.setRunType(RunModeConstants.PARALLEL.toString());
|
||||
|
|
|
@ -58,6 +58,7 @@ public class ApiScenarioParallelService {
|
|||
runRequest.setTestPlanReportId(request.getTestPlanReportId());
|
||||
runRequest.setHashTree(executeQueue.get(reportId).getHashTree());
|
||||
runRequest.setPlatformUrl(executionQueue.getDetailMap().get(reportId));
|
||||
runRequest.setRunType(RunModeConstants.PARALLEL.toString());
|
||||
if (LoggerUtil.getLogger().isDebugEnabled()) {
|
||||
LoggerUtil.debug("Scenario run-开始并发执行:" + JSON.toJSONString(request));
|
||||
}
|
||||
|
|
|
@ -43,6 +43,11 @@ public class APISingleResultListener extends MsExecListener {
|
|||
if (StringUtils.isNotEmpty(dto.getQueueId())) {
|
||||
CommonBeanFactory.getBean(ApiExecutionQueueService.class).queueNext(dto);
|
||||
}
|
||||
// 更新测试计划报告
|
||||
if (StringUtils.isNotEmpty(dto.getTestPlanReportId())) {
|
||||
LoggerUtil.info("Check Processing Test Plan report status:" + dto.getQueueId() + "," + dto.getTestId());
|
||||
CommonBeanFactory.getBean(ApiExecutionQueueService.class).testPlanReportTestEnded(dto.getTestPlanReportId());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LoggerUtil.error(e);
|
||||
}
|
||||
|
|
|
@ -34,6 +34,11 @@ public class MsKafkaListener {
|
|||
CommonBeanFactory.getBean(ApiExecutionQueueService.class).queueNext(testResult);
|
||||
// 全局并发队列
|
||||
PoolExecBlockingQueueUtil.offer(testResult.getReportId());
|
||||
// 更新测试计划报告
|
||||
if (StringUtils.isNotEmpty(testResult.getTestPlanReportId())) {
|
||||
LoggerUtil.info("Check Processing Test Plan report status:" + testResult.getQueueId() + "," + testResult.getTestId());
|
||||
CommonBeanFactory.getBean(ApiExecutionQueueService.class).testPlanReportTestEnded(testResult.getTestPlanReportId());
|
||||
}
|
||||
} else {
|
||||
// 更新报告最后接收到请求的时间
|
||||
if (StringUtils.equalsAny(testResult.getRunMode(), ApiRunMode.SCENARIO.name(),
|
||||
|
@ -41,7 +46,6 @@ public class MsKafkaListener {
|
|||
ApiRunMode.SCHEDULE_SCENARIO.name(), ApiRunMode.JENKINS_SCENARIO_PLAN.name())) {
|
||||
CommonBeanFactory.getBean(TestResultService.class).editReportTime(testResult);
|
||||
}
|
||||
|
||||
testResultService.saveResults(testResult);
|
||||
}
|
||||
LoggerUtil.info("执行内容存储结束");
|
||||
|
|
|
@ -201,7 +201,45 @@ public class ApiExecutionQueueService {
|
|||
return queue;
|
||||
}
|
||||
|
||||
public void testPlanReportTestEnded(String testPlanReportId) {
|
||||
// 检查测试计划中其他队列是否结束
|
||||
ApiExecutionQueueExample apiExecutionQueueExample = new ApiExecutionQueueExample();
|
||||
apiExecutionQueueExample.createCriteria().andReportIdEqualTo(testPlanReportId);
|
||||
List<ApiExecutionQueue> queues = queueMapper.selectByExample(apiExecutionQueueExample);
|
||||
if (CollectionUtils.isEmpty(queues)) {
|
||||
LoggerUtil.info("Normal execution completes, update test plan report status:" + testPlanReportId);
|
||||
CommonBeanFactory.getBean(TestPlanReportService.class).finishedTestPlanReport(testPlanReportId, TestPlanReportStatus.COMPLETED.name());
|
||||
} else {
|
||||
List<String> ids = queues.stream().map(ApiExecutionQueue::getId).collect(Collectors.toList());
|
||||
ApiExecutionQueueDetailExample example = new ApiExecutionQueueDetailExample();
|
||||
example.createCriteria().andQueueIdIn(ids);
|
||||
long count = executionQueueDetailMapper.countByExample(example);
|
||||
if (count == 0) {
|
||||
LoggerUtil.info("Normal execution completes, update test plan report status:" + testPlanReportId);
|
||||
CommonBeanFactory.getBean(TestPlanReportService.class).finishedTestPlanReport(testPlanReportId, TestPlanReportStatus.COMPLETED.name());
|
||||
|
||||
LoggerUtil.info("Clear Queue:" + ids);
|
||||
ApiExecutionQueueExample queueExample = new ApiExecutionQueueExample();
|
||||
queueExample.createCriteria().andIdIn(ids);
|
||||
queueMapper.deleteByExample(queueExample);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void queueNext(ResultDTO dto) {
|
||||
if (StringUtils.equals(dto.getRunType(), RunModeConstants.PARALLEL.toString())) {
|
||||
ApiExecutionQueueDetailExample example = new ApiExecutionQueueDetailExample();
|
||||
example.createCriteria().andQueueIdEqualTo(dto.getQueueId()).andTestIdEqualTo(dto.getTestId());
|
||||
executionQueueDetailMapper.deleteByExample(example);
|
||||
// 检查队列是否已空
|
||||
ApiExecutionQueueDetailExample queueDetailExample = new ApiExecutionQueueDetailExample();
|
||||
queueDetailExample.createCriteria().andQueueIdEqualTo(dto.getQueueId());
|
||||
long count = executionQueueDetailMapper.countByExample(queueDetailExample);
|
||||
if (count == 0) {
|
||||
queueMapper.deleteByPrimaryKey(dto.getQueueId());
|
||||
}
|
||||
return;
|
||||
}
|
||||
DBTestQueue executionQueue = this.handleQueue(dto.getQueueId(), dto.getTestId());
|
||||
if (executionQueue != null) {
|
||||
// 串行失败停止
|
||||
|
@ -211,7 +249,6 @@ public class ApiExecutionQueueService {
|
|||
return;
|
||||
}
|
||||
}
|
||||
|
||||
LoggerUtil.info("开始处理执行队列:" + executionQueue.getId() + " 当前资源是:" + dto.getTestId());
|
||||
if (executionQueue.getQueue() != null && StringUtils.isNotEmpty(executionQueue.getQueue().getTestId())) {
|
||||
if (StringUtils.equals(dto.getRunType(), RunModeConstants.SERIAL.toString())) {
|
||||
|
@ -222,16 +259,6 @@ public class ApiExecutionQueueService {
|
|||
if (StringUtils.equals(dto.getReportType(), RunModeConstants.SET_REPORT.toString())) {
|
||||
apiScenarioReportService.margeReport(dto.getReportId());
|
||||
}
|
||||
// 更新测试计划报告
|
||||
if (StringUtils.isNotEmpty(dto.getTestPlanReportId())) {
|
||||
ApiExecutionQueueDetailExample example = new ApiExecutionQueueDetailExample();
|
||||
example.createCriteria().andQueueIdEqualTo(dto.getQueueId());
|
||||
long count = executionQueueDetailMapper.countByExample(example);
|
||||
if (count == 0) {
|
||||
LoggerUtil.info("Normal execution completes, update test plan report status:" + dto.getTestPlanReportId());
|
||||
CommonBeanFactory.getBean(TestPlanReportService.class).finishedTestPlanReport(dto.getTestPlanReportId(), TestPlanReportStatus.COMPLETED.name());
|
||||
}
|
||||
}
|
||||
queueMapper.deleteByPrimaryKey(dto.getQueueId());
|
||||
LoggerUtil.info("Queue execution ends:" + dto.getQueueId());
|
||||
}
|
||||
|
|
|
@ -9,6 +9,6 @@
|
|||
</select>
|
||||
|
||||
<select id="findTestPlanRunningReport" resultType="java.lang.String">
|
||||
SELECT t1.id from test_plan_report t1 WHERE t1.`status` ="Running" and t1.id NOT IN (SELECT t.report_id from api_execution_queue t);
|
||||
SELECT t1.id from test_plan_report t1 WHERE t1.`status` ="Running" and t1.id NOT IN (SELECT t.report_id from api_execution_queue t where t.report_id is not null);
|
||||
</select>
|
||||
</mapper>
|
Loading…
Reference in New Issue